How to Edit InfoPath XML File in Forum Library Programmatically in SharePoint 2007

The below lines of code snippet is to update the infopath xml record(file)

SPWeb _web = SPContext.Current.Web; 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”, ““);

doc.DocumentElement.SelectSingleNode(“my:Status”, nameSpaceManager).InnerText = “Saved”; […]

“The file has been modified by SHAREPOINT\system” Error while Updating InfoPath xml file in SharePoint Library

If you try to update the InfoPath xml file through object model in events/WebParts or through any medium.

While execting the Item.Update() will cause the below error. While updating the InfoPath xml file in ListItem the file and ListItem object getting disconnected.

Item.File.Update() will solve your issue.

StackTrace […]