Beantwortet How to load xml document content from a SP list/library?

  • יום שלישי 01 מאי 2012 20:23
     
     

    I have a form list/library in SharePoint, which consists of InfoPath forms, they are all in xml format.

    Now, I need to go through all the xml files and retrieve some of its content. But I have no idea what code I have to write in order to get the xml document loaded onto. I have something like this, what should I do in the bolded section below?

    PList formLibrary =   newSite.AllWebs[strServerURL].Lists[libraryName];
    SPListItemCollection collListItems = formLibrary.Items;
    foreach (SPListItem oListItem in collListItems)
    {
        {
    ??? what should I do here ??? Where formXML will be the text of the file.

      XmlDocument doc = new XmlDocument();
                            doc.InnerXml = formXML;
                            XmlNamespaceManager xNameSpace = InitNamespaceManager(doc);
                            XPathNavigator xNavMain = doc.CreateNavigator();

    Thanks in advance, your help would be greatly appreciated.

כל התגובות

  • יום שלישי 01 מאי 2012 20:31
     
     

    You can use XmlDocument.Load(formXML). After this you can use xpath queries to get child nodes. You can also use Xml.Linq and the XElement and XDocument classes.

    http://msdn.microsoft.com/en-us/library/ms256086.aspx

    http://msdn.microsoft.com/en-us/library/bb387098.aspx


    Blog | SharePoint Field Notes Dev Tool | ClassMaster

  • יום שלישי 01 מאי 2012 22:08
     
     

    Hi,

    Actually, I would like to know how I can get the value of "formXML" out of the SP list, that is how can I load the string value to this  variable formXML from a SP list/file,

    formXML = loadString(SPlistitem.file.url) <-- something like this, what will be the method?

    Thanks.

  • יום רביעי 02 מאי 2012 13:50
     
     תשובה

    I was able to get this working with the following code.

    Stream fStream = oListItem.File.OpenBinaryStream() ;

    byte[] MyData = new byte[fStream.Length];
    fStream.Read(MyData, 0, (int)fStream.Length);
    string formXML = Encoding.Unicode.GetString(MyData);
    formXML = Encoding.UTF8.GetString(MyData);

    • סומן כתשובה על-ידי wkpli יום רביעי 02 מאי 2012 13:50
    •