C# XmlConvert和SharePoint内部字段不相等

C# XmlConvert和SharePoint内部字段不相等,c#,sharepoint-2010,C#,Sharepoint 2010,根据代码在SharePoint中创建了columnField 已将内容类型添加到SharePoint While getting the field name from the Sharepoint i get the following: PD_FILE_PART_x002e_PD_POPEN_DATE_x003b_DOCSADM_x002e_PD_FILE_PART_x002e_SYSTEM_ID while setting the same field from the Code us

根据代码在SharePoint中创建了columnField 已将内容类型添加到SharePoint

While getting the field name from the Sharepoint i get the following:
PD_FILE_PART_x002e_PD_POPEN_DATE_x003b_DOCSADM_x002e_PD_FILE_PART_x002e_SYSTEM_ID 

while setting the same field from the Code using:

 Here **strContentTypeField** passed parameter from another function.

 SPWeb web = null;
            try
            {
                web = DEUtilityInternal.CreateSPWebObject(siteUrl);
                SPList spList = web.Lists.GetList(new Guid(strListName), false);
                if (spList.ContentTypes.Count > 0)
                {
                    for (int i = 0; i < fieldsToBeAdded.Count; i++)
                    {
                        string strContentTypeField = fieldsToBeAdded[i];
                        if (spList.ContentTypes[contentTypeName].FieldLinks[strContentTypeField] != null) continue;

                        if (!spList.Fields.ContainsField(strContentTypeField))
                        {
                            if (!spList.Fields.ContainsField(XmlConvert.EncodeName(strContentTypeField)))
                                continue;
                            else
                                strContentTypeField = XmlConvert.EncodeName(strContentTypeField);
                        }
                    }
                }
            }

Thanx提前

您可以通过以下方式实现:)


是的@Binayachary…这对我也很有用!!!我完全按照你说的做了…而且它完全按照我想要的工作!!!
PD_FILE_PART_x002e_PD_POPEN_DATE_x003B_DOCSADM_x002e_PD_FILE_PART_x002e_SYSTEM_ID 

so while comparing the field I cannot return the value true.

 What can I do for getting the value equal??
 var encodedFieldName=XmlConvert.EncodeName(strContentTypeField);
                        // SharePoint fields are case sensitive , xmlconvert provides Hex characters in upper case while sharepoint stores in lowercase
                        encodedFieldName = Regex.Replace(encodedFieldName, @"[_][x][A-Fa-f0-9]+[_]", m =>m.ToString().ToLower());
                        if (!spList.Fields.ContainsField(encodedFieldName))
                        {
                            encodedFieldName = EncodeToInternalField(encodedFieldName);
                            if (!spList.Fields.ContainsField(encodedFieldName))
                                continue;
                            strContentTypeField = encodedFieldName;
                        }

 private string EncodeToInternalField(string toEncode)
    {

        if (toEncode != null)
        {              

            StringBuilder encodedString = new StringBuilder();   
            foreach (char chr in toEncode.ToCharArray())
            {
                string encodedChar = HttpUtility.UrlEncodeUnicode(chr.ToString());                   

                if (encodedChar == "+" || encodedChar == " ")
                {
                    encodedString.Append("_x0020_");
                }
                else if (encodedChar == ".")
                {
                    encodedString.Append("_x002e_");
                }
                else
                {
                    encodedString.Append(chr);
                }

            }
            return encodedString.ToString();
        }
        return null;
    }