How can I save SPList in XML?
-
07-10-2020 - |
Question
I have some SPLists in my SP.
I take some one List like that Guid listGuid = Guid.Parse(listID);
and watch id SPList list = web.Lists[listGuid];
.
But i don't know how i can save list
in xml file in folder list?
p.s.: when i say folder list I'm talking about list.RootFolder
.
Solution
String myURL = "<your site URL>/_vti_bin/owssvr.dll?Cmd=Display&List={List GUID}&XMLDATA=TRUE";
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(myURL);
myRequest.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
Encoding enc = System.Text.Encoding.GetEncoding(0);
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), enc);
string result = reader.ReadToEnd();
You can chuck this URL into your browser as well and you'll get back your list data in XML. You can include the GUID of a view to filter what comes back:
http://<site url>/_vti_bin/owssvr.dll?Cmd=Display&List=<listid>&View=<view guid>&Query=*&XMLDATA=TRUE
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange