1

I am reading the values of the List using CSOM. Some List items contains double quotes in the field values. When I read the its value double quotes are replaced by & quot; . How can I get the value displayed in the List?enter image description here

string siteCollectionUrl = "https://tenantname.sharepoint.com/sites/sitename";
string userName = "username@tenant.onmicrosoft.com";
string password = "yourpassword";

// Namespace: Microsoft.SharePoint.Client  
ClientContext ctx = new ClientContext(siteCollectionUrl);

// Namespace: System.Security
SecureString secureString = new SecureString();
password.ToList().ForEach(secureString.AppendChar);

// Namespace: Microsoft.SharePoint.Client  
ctx.Credentials = new SharePointOnlineCredentials(userName, secureString);

// Namespace: Microsoft.SharePoint.Client  
Site site = ctx.Site;

ctx.Load(site);
ctx.ExecuteQuery();
Web web = ctx.Web;

ctx.Load(web,w => w.ServerRelativeUrl,w => w.Lists);

List list = web.Lists.GetByTitle("List1");

ctx.Load(list);
CamlQuery camlQuery = new CamlQuery();
ListItemCollection itemColl = list.GetItems(camlQuery);

ctx.Load(itemColl);
ctx.ExecuteQuery();
foreach (ListItem item in itemColl)

{
    Console.WriteLine(item["Title"].ToString());
    foreach (var fieldValue in item.FieldValuesAsHtml.FieldValues)
    {
        Console.WriteLine(fieldValue.Key);
        Console.WriteLine(fieldValue.Value);//double quotes are replaced by " 
        //eg. Check for "Continue demo.." button. is getting as
        //Check for "Continue demo.." button.
    }
}
2

You can use WebUtility.HtmlDecode(string) method to decode the Html encoded strings and get the actual values as displayed in the List.

using System.Net;


foreach (ListItem item in itemColl)

{
    Console.WriteLine(item["Title"].ToString());
    foreach (var fieldValue in item.FieldValuesAsHtml.FieldValues)
    {
        Console.WriteLine(fieldValue.Key);
        Console.WriteLine(WebUtility.HtmlDecode(fieldValue.Value));
    }
}

you can also replace all " with " but that would only replace double quotes and if there are any other html encodes like > < above code will take care of it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.