Tuesday, January 24, 2012

Programmatically reading the contents from an InfoPath form

            using (SPSite oSite = new SPSite(SPContext.Current.Site.ID))
            {
                using (SPWeb oWeb = oSite.OpenWeb())
                {
                    SPList formsLib = oWeb.Lists["My Forms"];
                    if (formsLib != null)
                    {
                        foreach (SPListItem item in formsLib.Items)
                        {
                            MemoryStream stream = new MemoryStream(item.File.OpenBinary());
                            XmlDocument doc = new XmlDocument();
                            doc.Load(stream);
                            XmlNamespaceManager nameSpaceManager = new XmlNamespaceManager(doc.NameTable);
                            nameSpaceManager.AddNamespace("my", doc.DocumentElement.NamespaceURI);
                            XmlNodeList nodeList;
                            XmlElement root = doc.DocumentElement;
                            string username = root.SelectSingleNode("/my:myFields/my:userName", nameSpaceManager).InnerText;
                            nodeList = root.SelectNodes("/my:myFields/my:prjdetails/my:group", nameSpaceManager);
                            foreach (XmlNode node in nodeList)
                            {
                                projName = node.SelectSingleNode("my:project", nameSpaceManager).InnerText;
                                projID = node.SelectSingleNode("my:projID", nameSpaceManager).InnerText;
                            }
                        }
                    }
                }
            }

1 comment:

  1. Please upload your InfoPath form Design Screen shot.

    Thanks

    ReplyDelete

How to launch a document by clicking a link to the file?

Word: <a href='ms-word:ofe|u|path/to/web/word/document.docx'>Link to document</a> Excel: <a href='ms-excel:o...