Load SharePoint 2007 List into DataTable


I have been playing around with the Web Services provided by SharePoint and thought this code example might help someone else as it took me a bit to track down.

private ListService.Lists listService = new ListService.Lists();
private void LoadList(string listName) {

   XmlDocument doc = new XmlDocument();
   XmlNode listQuery = doc.SelectSingleNode("//Query");
   XmlNode listViewFields = doc.SelectSingleNode("//ViewFields");
   XmlNode listQueryOptions = doc.SelectSingleNode("//QueryOptions");
   XmlNode node;

   listService.UseDefaultCredentials = true;
   listService.Url = "http://localhost/_vti_bin/Lists.asmx";
   node = listService.GetListItems(listName, string.Empty, listQuery, listViewFields, "0", listQueryOptions, string.Empty);
   XmlTextReader reader = new XmlTextReader(node.OuterXml, XmlNodeType.Element, null);
   DataSet ds = new DataSet();
   DataTable table = ds.Tables["row"];


About Wes MacDonald

Wes MacDonald is a DevOps Consultant for LIKE 10 INC., a DevOps consulting firm providing premium support, guidance and services for Azure, Microsoft 365 and Azure DevOps.

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: