Return Your SharePoint List Items In XML
A reader (people read this crap?!?!?!) asked me how to return SharePoint list items in XML. It’s very easy!
Say you want to run a simple return with some very simple parameter types:
- returnListItemsXML(list.Items);
this is pretty simple! But we haven’t built the returnListItemsXML method yet :-)
Firstly, build up your method file with its name decoration and parameter types:
- public static XmlDocument returnListItemsXML(SPListItemCollection listItems)
You can see that we are passing in an SPListItemCollection in order to to get all the items from the relevant list (which is why in the primary method we are using list.Items).
Next, you must create a new XmlDocument object in order to represent an XML document :
- XmlDocument document = new XmlDocument();
Next, build a small if condition in order to check whether the the list items return a null value or not. If they do not, there is something that can be loaded into the XML document.
- if (listItems != null)
- {
- }
Then, load the XML document with the list items:
- document.LoadXml(listItems.Xml);
so, afterwords you would have this:
- if (listItems != null)
- {
- document.LoadXml(listItems.Xml);
- }
otherwise, just return the document:
- return document;
That’s it! Very simple indeed :-)
5 Comments
Trackbacks/Pingbacks
- Links (6/24/2007) « Steve’s SharePoint Stuff - [...] Return Your SharePoint List Items In XML [...]
- Bookmarks for March 8th through March 9th | Peng's Blog - [...] Return Your SharePoint List Items In XML | ARB Security Solutions – [...]
Articles & Research
SharePoint Security
SharePoint Development
SharePoint Architecture
Claims Authentication
Forefront For SharePoint
AIS / Dynamics GP
Team Foundation Server
Pex And Moles
ISA/TMG/IAG/UAG
DPM
Cardspace
Research Methodology
Rural ICT Development
Numerical Analysis
Multi-Level Research
Knowledge Management
Personal/Off-Topic
Hi, can you provide the full sample code for this? Thank you.
Thank you for your coding,
would you please provide the whole of the coding for me, it is interesting for this, however, how to write this coding.
Hi, i’m looking to do this, but am very new to c# and SahrePoint. Do you have any more information?
Cheers keep doing what your doing!
Excellent work. Somehow, I am getting an error though! Is there something I am missing?
You would have to say the error.