The below lines of code snippet is to update the infopath xml record(file)
SPList _list = _web.Lists[“SampleFormLib”];
MemoryStream myInStream = new MemoryStream(item.File.OpenBinary());
XmlTextReader reader = new XmlTextReader(myInStream);
XmlDocument doc = new XmlDocument();
doc.Load(reader);
reader.Close();
myInStream.Close();
XmlNamespaceManager nameSpaceManager = new XmlNamespaceManager(doc.NameTable);
nameSpaceManager.AddNamespace(“my”, “http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-06-11T12:44:57“);
doc.DocumentElement.SelectSingleNode(“my:Status”, nameSpaceManager).InnerText = “Saved”;
doc.DocumentElement.SelectSingleNode(“my:SaveDate”, nameSpaceManager).InnerText = DateTime.Today.ToString();
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
SPFile newFile = _web.Folders[“SampleFormLib”].Files.Add(item.File.Name.ToString(), (encoding.GetBytes(doc.OuterXml)), true);
item.File.Update();
Make sure you execute item.File.Update() to commit the changes (I got the errors while execute item.Update() and spent couple of hours to find 🙁 )
Have you considered adding some differing opinions to your article? I think it might enhance viewers understanding.