Thursday, September 18, 2014

Get Field value as text

I have seen many developers struggling to fetch text value from Multi line/ Choice column of sharepoint list or library , below is easiest way to achieve this

            SPSite site = SPContext.Current.Site;
            SPWeb web = site.OpenWeb();
            SPList declarationList = web.Lists["DeclarationContent"];
            SPListItem item = declarationList.Items[0];
            string content = item.Fields["declaration"].GetFieldValueAsText(item["declaration"]);


if u observe the above code item.Fields["declaration"] contains method GetFieldValueAsText
which accepts the value of column and it will convert the html or drop down /choice content into text value.

Happy Coding !! 

No comments:

Post a Comment