0

I am fetching data from sharepoint list for a multi line column. And then split the data by space and comparing it to other string but despite the value in both the strings being same it gives false result.

Please follow the below code:

    string[] strBodys = SPHttpUtility.ConvertSimpleHtmlToText(Convert.ToString(workflowProperties.ListItem[SCMSConstants.lstfldBody]), Convert.ToString(workflowProperties.ListItem[SCMSConstants.lstfldBody]).Length).Split(' ');

bool hasKwrdInBody = false;
foreach (SPItem oItem in oColl)
                        {//get all the keywords
                            string[] strkeyWrds = SPHttpUtility.ConvertSimpleHtmlToText(Convert.ToString(oItem[SCMSConstants.lstfldKWConfigKeywordsIntrName]), Convert.ToString(oItem[SCMSConstants.lstfldKWConfigKeywordsIntrName]).Length).Split(',');
//in body
                            foreach (string strKW in strkeyWrds)
                            {
                                string KWValue = strKW.Trim(' ').ToLower();
                                foreach (string strBdy in strBodys)
                                {
                                    string BodyValue = strBdy.Trim(' ').ToLower();
                                    //if (strKW.ToLower().Equals(strBdy.ToLower()))
                                    if(KWValue == BodyValue) //here it always gives false result
                                    {
                                        hasKwrdInBody = true;
                                        break;
                                    }
                                }
                                if (hasKwrdInBody)
                                    break;
                            }

                            if (!hasKwrdInSbjct && !hasKwrdInBody)
                            {
                                continue;
                            }
                            else
                            {
                                //set business unit to current groups rule
                                bsnsUnitLookupFld = new SPFieldLookupValue(Convert.ToString(oItem[SCMSConstants.lstfldBsnsUnit]));                                
                                asgndTo = new SPFieldUserValue(objWeb,Convert.ToString(oItem[SCMSConstants.lstfldKWConfigAssignedToIntrName])).User;
                                groupName = Convert.ToString(oItem[SCMSConstants.lstfldKWConfigAssignedToGroupIntrName]).Split('#').Last();
                                break;
                            }
}

Please mind that i am trying to get multi line text from sharepoint list Please provide your suggestions.

Rehan
  • 19
  • 1
  • 6

2 Answers2

0

That also depends on the exact type of your Multiline field (e.g Plain Text or RichText, etc.). Maybe it would be clear if you just added some logging writing out the values you are comparing.

For details on how to get the value of a Multiline textfield check Accessing Multiple line of text programmatically and here for RichText

Community
  • 1
  • 1
Simone
  • 1
0

I got it working by comparing and counting the characters in both the strings. Actually some UTC codes were embedded in to the string. First I removed those characters using regular expression and then compared them and it worked like a charm.

Here is the code snippet, might help some one.

string[] strBodys = SPHttpUtility.ConvertSimpleHtmlToText(Convert.ToString(workflowProperties.ListItem[SCMSConstants.lstfldBody]), Convert.ToString(workflowProperties.ListItem[SCMSConstants.lstfldBody]).Length).Split(' ');

bool hasKwrdInBody = false;
foreach (SPItem oItem in oColl)
                        {//get all the keywords
                            string[] strkeyWrds = SPHttpUtility.ConvertSimpleHtmlToText(Convert.ToString(oItem[SCMSConstants.lstfldKWConfigKeywordsIntrName]), Convert.ToString(oItem[SCMSConstants.lstfldKWConfigKeywordsIntrName]).Length).Split(',');
//in body
                            foreach (string strKW in strkeyWrds)
                            {
                                string KWValue = strKW.Trim(' ').ToLower();
KWValue = Regex.Replace(KWValue, @"[^\u0000-\u007F]", string.Empty); //here replaced the utc codes
                                foreach (string strBdy in strBodys)
                                {
                                    string BodyValue = strBdy.Trim(' ').ToLower();

 BodyValue = Regex.Replace(BodyValue, @"\t|\n|\r", string.Empty); // new code to replace utc code
                                                BodyValue = Regex.Replace(BodyValue, @"[^\u0000-\u007F]", string.Empty); //new code to replace utc code

                                    //if (strKW.ToLower().Equals(strBdy.ToLower()))
                                    if(KWValue == BodyValue) //here it always gives false result
                                    {
                                        hasKwrdInBody = true;
                                        break;
                                    }
                                }
                                if (hasKwrdInBody)
                                    break;
                            }

                            if (!hasKwrdInSbjct && !hasKwrdInBody)
                            {
                                continue;
                            }
                            else
                            {
                                //set business unit to current groups rule
                                bsnsUnitLookupFld = new SPFieldLookupValue(Convert.ToString(oItem[SCMSConstants.lstfldBsnsUnit]));                                
                                asgndTo = new SPFieldUserValue(objWeb,Convert.ToString(oItem[SCMSConstants.lstfldKWConfigAssignedToIntrName])).User;
                                groupName = Convert.ToString(oItem[SCMSConstants.lstfldKWConfigAssignedToGroupIntrName]).Split('#').Last();
                                break;
                            }
}
Rehan
  • 19
  • 1
  • 6