views:

22

answers:

2

Hi,

I was successfully able to update one of the fields (which was of type boolean) from infopath for library item using sharepoint object Model as if it was a list item.

But for another field which is of type text, the same code just gets executed but does not change the field value !!!!

I am using following code, which works for that boolean field but for another field of type string , not sure why it is not workign. Any idea ?

SPSecurity.RunWithElevatedPrivileges(delegate()

{ SPWeb web;

SPSite site = new SPSite("http://sharepointsite"); web = site.OpenWeb();

SPList formLibList = web.Lists["FormLibraryName"];

SPQuery query = new SPQuery(); query.Query = "" + titleName + ""; web.Site.WebApplication.FormDigestSettings.Enabled = false;

web.AllowUnsafeUpdates = true; SPListItemCollection col = formLibList.GetItems(query);

if (col.Count > 0) {

col[0]["CustomerName"] = "test customer name"; col[0].Update();

}

web.Site.WebApplication.FormDigestSettings.Enabled = true; web.AllowUnsafeUpdates = false; });

Thanks,

Nikhil

A: 

I had to declare SPListItem and set it instead of directly modifying list item collection.

Nikhil Vaghela
A: 

It's not an answer to your question (you already found the solution yourself), but you may want to put your SPSite and SPWeb objects in a using block. In your example code you are not disposing them, which results in a memory leak. The correct way would be like this:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    using (SPSite site = new SPSite("http://sharepointsite"))
    {
        using (SPWeb web = site.OpenWeb())
        {
            // the rest of your code
        }
    }
});
Tom Vervoort
Yes,Thanks for pointing it out.
Nikhil Vaghela