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