kamagra how much to take

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:

  1. 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:

  1. 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 :

  1. 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.

  1. if (listItems != null)
  2. {
  3. }

Then, load the XML document with the list items:

  1. document.LoadXml(listItems.Xml);

so, afterwords you would have this:

  1. if (listItems != null)
  2. {
  3. document.LoadXml(listItems.Xml);
  4. }

otherwise, just return the document:

  1. return document;

That’s it! Very simple indeed :-)


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>