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;
Response.Write(strValue);
//XML Namespace Creator
private 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;
}
No comments:
Post a Comment