Programmatically generate/update data for an InfoPath Form and save it in a SharePoint Form Library
Steps 1) Create an Infopath form using the Microsoft InfoPath desinger. and publish the infoPath form into respective form library. I also created an empty form in the form library based on this template (BLANK.xml). This example opens an empty form (BLANK.xml) from the form library, reads it into an xml document, parses the xml document to update the fields, and then saves the xml document as a new file back to the form library. 2) // opens the site SPWeb webSite = new SPSite(txtUrl.Text).OpenWeb(); // gets the blank file to copy SPFile BLANK = webSite.Folders["Test1"].Files["BLANK.xml"]; // reads the blank file into an xml document MemoryStream inStream = new MemoryStream(BLANK.OpenBinary()); XmlTextReader reader = new XmlTextReader(inStream); XmlDocument xd = new XmlDocument(); xd.Load(reader); reader.Close(); inStream.Close(); //gets the root element from the xml document XmlElement root = xd.DocumentElement; //the loop counter is started at 2 to skip ...