使用反斜杠和双引号来解决问题

时间:2012-09-13 15:00:21

标签: c# sharepoint escaping

在sharepoint中为了翻译字段,我必须修改一个名为schemaxml的属性。

当我用c#读取它时,我得到的代码是这样的:

  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();

值未被更改。

enter image description here

1 个答案:

答案 0 :(得分:1)

试试这个:

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

差异为"DisplayName=\""而非@"DisplayName=\"