Luis Valencia
Luis Valencia

Reputation: 33998

Escaping issues with backslashes and double quotes

In sharepoint in order to have a field translated I have to modify one attribute which is called schemaxml.

When I read it using c# the code I get is something like this:

  string schemaXmlWithResourceTokens = recurrentField.SchemaXmlWithResourceTokens;
  int startIndex = schemaXmlWithResourceTokens.IndexOf("\"", schemaXmlWithResourceTokens.IndexOf("DisplayName=\"")) + 1;
  int endIndex = schemaXmlWithResourceTokens.IndexOf("\"", startIndex);
  int substringLength = endIndex - startIndex;
  string value = @"DisplayName=\" + schemaXmlWithResourceTokens.Substring(startIndex, substringLength);
  schemaXmlWithResourceTokens = schemaXmlWithResourceTokens.Replace(value, @"DisplayName=\$Resources:SPNLMeetings,Field_Recurrent_Name");
  recurrentField.SchemaXml = schemaXmlWithResourceTokens;
  recurrentField.Update();

The values is not being changed.

enter image description here

Upvotes: 0

Views: 375

Answers (1)

Steve Konves
Steve Konves

Reputation: 2668

Try this:

string value = "DisplayName=\"" + schemaXmlWithResourceTokens.Substring(startIndex, substringLength);

The difference being "DisplayName=\"" instead of @"DisplayName=\"

Upvotes: 1

Related Questions