Update infopath form field value in sharepoint document library using codes - InfoPath Dev
in

InfoPath Dev

Update infopath form field value in sharepoint document library using codes

Last post 08-17-2009 08:37 AM by Hilary Stoupa. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 08-14-2009 07:38 PM

    Update infopath form field value in sharepoint document library using codes

    Hi all,

    I am trying to update documents in an infopath document library in sharepoint. I got "Object Reference not set to an instance of an object" error when try to retrieve a node value.

    codes listed below, Thanks for the help.

                SPSite l_site = new SPSite(textBox1.Text);
                SPWeb l_web = l_site.OpenWeb();
                SPList l_list = l_web.Lists[textBox2.Text];

                foreach (SPListItem objListItem in l_list.Items)
                {
                    SPFile l_file = objListItem.File;
                    l_file.CheckOut();
                    XmlDocument l_xmlFile = new XmlDocument();
                    l_xmlFile.Load(l_file.OpenBinaryStream());
                    XmlNode l_xmlRootNode = l_xmlFile.DocumentElement;
                    XPathNavigator l_xmlNav = l_xmlFile.CreateNavigator();
                    XmlNamespaceManager l_nsmgr = new XmlNamespaceManager(l_xmlFile.NameTable);
                    l_nsmgr.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-08-15T09:27:20");

                    string temp2 = l_xmlNav.SelectSingleNode("/my:myFields/my:Financial/my:test", l_nsmgr).Value;   <--- ERROR HERE, I am sure the XML path is correct
                    l_xmlRootNode.SelectSingleNode("/my:myFields/my:Financial/my:test", l_nsmgr).InnerText = "1";
                    
                    MemoryStream l_msFile = new MemoryStream(Encoding.UTF8.GetBytes(l_xmlFile.OuterXml));
                    l_file.SaveBinary(l_msFile);
                    l_file.CheckIn("System Auto Correction on Go & Get",SPCheckinType.MinorCheckIn);
                }

     Regards, john

  • 08-17-2009 08:37 AM In reply to

    Re: Update infopath form field value in sharepoint document library using codes

    Modify your code to first create an XPathNavigator to the "my:test" node, then try to get the value. Put a breakpoint by the line where you try to get the value and run in debug. Usually if you get this error, it is because you are not successfully selecting the node, which means the result of SelectSingleNode is null....Did you use Copy Xpath in the data source task pane to get the XPath for the field?

    Hilary Stoupa

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