Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Update # comments field in Sharepoint blog post list programatically

$
0
0

Hi,

I want to update # comments (NumComments) in the blog post. i moved the comments list to SQL and i am planning to maintain same Post list for my blog and other details like numcomments. The column type is "Lookup". Is this possible to update the column. Please advice me. i am using the below code.

            SPSite site = new SPSite("http://msite:1000/");
            SPWeb web = site.OpenWeb("/myblog");
            SPList list = web.Lists["Posts"];
            SPListItem item = list.GetItemById(13);
            SPFieldLookupValue values = new SPFieldLookupValue();
            String fieldValue = "18;#12";
            values = new SPFieldLookupValue(fieldValue);
            SPListItem targetItem = list.GetItemById(13);
            targetItem.Fields["# Comments"].ReadOnlyField = true;
            targetItem["# Comments"] = values.ToString();
            targetItem.SystemUpdate();
            list.Update();

Thanks

P.S : Its not showing any error. But the value is not updating in post list



Viewing all articles
Browse latest Browse all 11571

Trending Articles