// Getting data from infopath library
SPSite objSite = new SPSite("http://sharepointsvr:123/"); SPWeb objWeb = objSite.RootWeb; SPList objList = objWeb.Lists["Participant"]; SPQuery objQuery = new SPQuery (); SPListItemCollection objCollection = objList.GetItems(objQuery); SPListItem objItem = objCollection[0]; SPFile objFile = objItem.File; byte[] xmlFormData = objFile.OpenBinary(); XPathDocument ipForm = null; using (MemoryStream ms = new MemoryStream(xmlFormData)) { ipForm = new XPathDocument(ms); ms.Close(); } XPathNavigator ipFormNav = ipForm.CreateNavigator(); XPathNavigator nodeNav = ipFormNav.SelectSingleNode("/my:myFields/my:fldFamilyName", GetFormNSM(ipForm)); string strValue = nodeNav.InnerXml;
//XML Namespace Creator, this is changing with your infopath libraryprivate XmlNamespaceManager GetFormNSM(XPathDocument ipForm) { const string strMYNamespacePrefix = "my"; const string strMYNamespaceURI = "http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-06-25T10:50:10"; const string strDIRNamespacePrefix = "d"; const string strDICNamespaceURI = "http://schemas.microsoft.com/sharepoint/soap/directory/"; XPathNavigator formAccess = ipForm.CreateNavigator(); XmlNamespaceManager namespaceMngr = new XmlNamespaceManager(formAccess.NameTable); namespaceMngr.AddNamespace(strMYNamespacePrefix, strMYNamespaceURI); namespaceMngr.AddNamespace(strDIRNamespacePrefix, strDICNamespaceURI); return namespaceMngr; }