Can InfoPath code behind update SharePoint list metadata? - InfoPath Dev
in

InfoPath Dev

Can InfoPath code behind update SharePoint list metadata?

Last post 03-13-2012 10:26 AM by gombear. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 02-08-2012 02:41 PM

    Can InfoPath code behind update SharePoint list metadata?

    Hi,

    I'm trying to update one of field in SharePoint list using code behind from InfoPath form.   With below code, I'm getting The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.   I tried additional code with commented out statements too, but same problem.

    Is it possible to update SharePoint metadata from InfoPath code behind?  I can upload/create new list and delete wihtout a problem, but update fails. 

    Thanks.

    string tempStrUrl = http://server;

    string listName = "LibName";

    string fileName = "xyz.txt";

    SPSecurity.RunWithElevatedPrivileges(delegate()

    {

    using (SPWeb site = new SPSite(tempStrUrl).OpenWeb())

    {

    //Microsoft.SharePoint.Administration.
    SPWebApplication webApp = site.Site.WebApplication;

    //webApp.FormDigestSettings.Enabled = false;

    site.AllowUnsafeUpdates = true;

    tempLocation = tempStrUrl + "/" + listName + "/" + fileName;

    try

    {

    SPListItem item = site.GetListItem(tempLocation);if (null != item)

    {

    item[
    "Status"] = "Finalize";

    //item.SystemUpdate();

    item.Update();

    }

    }

    catch (Exception ex)

    {

    string v = ex.Message;

    }

    //webApp.FormDigestSettings.Enabled =
    true;site.AllowUnsafeUpdates = false;

    }

    });

  • 02-16-2012 01:02 PM In reply to

    Re: Can InfoPath code behind update SharePoint list metadata?

    Make sure to set AllowUnsafeUpdates on both the SPSite and SPWeb objects

    using (SPSite site = new SPSite(tempStrUrl))

    {

        site.AllowUnsafeUpdates = true;    

        using (SPWeb web = site.OpenWeb())

        {

            web.AllowUnsafeUpdates = true;

    ...

     

     

  • 02-16-2012 02:09 PM In reply to

    Re: Can InfoPath code behind update SharePoint list metadata?

    Hi Jim,

    Thank you for your suggestion.

    But now I'm getting "Operation is not valid due to the current state of the object." error.

    Still it can not update SharePoint data.

    I'm executing this while the form is in workflow in case if this makes difference.

    Thanks.

  • 03-13-2012 10:26 AM In reply to

    Re: Can InfoPath code behind update SharePoint list metadata?

    In case if anybody has same problem.  

    I find out from SPTechCon that it can't be done.

    Infopath can't update SharePoint metadata.   It can add, but not change the value of metadata.

Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.