Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# XML Sharepoint
Hello!
 
I ran into a problem editing an existing XML file in a sharpoint documents library..
What I want to do is search for an xml file(based on its namem), and when its found, load it into an XmlDocument so it can be edited...
this is what I got so far... When I run this code, the file/item Im searching for is found(lets say test.xml), but the problem is I dont know how to load it into the xmldocument for editing...Or am I doing this the wrong way? :P
 
Thank you for your answers...
 
public XmlDocument GetXMLDocument(string name)
{
    
    XmlDocument document = new XmlDocument();
    SPListItemCollection items = GetList(libraryName).Items;//gets the list

    foreach (SPItem item in items)
    {
        if (item.Name == name)
            document.Load(item); //I get lost here :)
    }
    
    return document;
}
Posted 4-Jul-12 3:01am
pykos546

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Ok so I think I found a solution, dont know if its the best but for now it servs our purpose... What this does is preaty straight forward.
I open the file as a binary array wich is loaded into a stream so it can be used in xmldocument.load method, to be procesed... If there is a better way of doing it, please tell me Smile | :)
 
public XmlDocument GetXMLDocument(string name)
{
    XmlDocument document = new XmlDocument();
    SPWeb site = GetSite();
 
    string fileUrl = _url + libraryname + "/" + name;
    SPFile temp = site.GetFile(fileUrl);
    
    byte[] table = temp.OpenBinary();
    MemoryStream stream = new MemoryStream(table);
 
    document.Load(stream);
    //clear resources
    stream.Dispose();
    return document;
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 449
1 ChintanShukla 305
2 Sergey Alexandrovich Kryukov 293
3 RyanDev 250
4 Richard Deeming 250
0 Sergey Alexandrovich Kryukov 8,906
1 OriginalGriff 7,601
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,923


Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 5 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100