Welcome to MSDN Blogs Sign in | Join | Help

SharePoint Web Service Example – Grabbing Wiki Content

I presented a session at Tech Ready (Microsoft internal conference) yesterday. One of the samples I showed was how information can be consumed from a SharePoint web service and repurposed. The specific example was taking the Wiki content we host internally on our FAQ site (it's a great example of using Wikis to build a Frequently Asked Questions knowledgebase) and creating an html file from it.

The code sample is straightforward. I developed it using Visual C# Express Edition on my Vista laptop. The web reference I added was http://faq/sites/sharepoint/_vti_bin/lists.asmx.

In this particular sample, I retrieve content from a specific view. In that view, I've actually added the Wiki Content field which is why the content is returned. Instead of getting content from a specific view, I could have specified a query and the fields I wanted returned as parameters to the web service.

Here's the sample:

SharePoint_FAQ_Lists.Lists ls = new SharePoint_FAQ_Lists.Lists();

ls.Credentials = System.Net.CredentialCache.DefaultCredentials;

string url = "http://faq/sites/sharepoint";

ls.Url = url + @"/_vti_bin/lists.asmx";

 

//get all wiki pages from the "Wiki Pages" library from a particular view. The second parameter is the GUID of the view

XmlNode wListItems = ls.GetListItems("Wiki Pages", "{3F1DB907-7D89-4139-99EC-443D1F9BECC7}", null, null, "", null, "");

 

//assemble the html content that will eventually

string htmlBody = "<html><body>";

 

//iterate through the returned XML and parse out the relevant information

foreach (XmlNode outerNode in wListItems.ChildNodes)

{

if (outerNode.NodeType.Equals(System.Xml.XmlNodeType.Element))

{

foreach (XmlNode node in outerNode.ChildNodes)

{

if (node.NodeType.Equals(System.Xml.XmlNodeType.Element))

{

XmlNode nameNode = node.Attributes.GetNamedItem("ows_LinkFilename");

XmlNode wikiNode = node.Attributes.GetNamedItem("ows_WikiField");

 

String wikiName = nameNode.InnerText;

String wikiBody = wikiNode.InnerText;

 

htmlBody += "<a href=\"" + "http://faq/sites/sharepoint/wiki pages/"+ wikiName + "\">" + wikiName + "</a><br>";

htmlBody += wikiBody;

}

}

}

}

 

htmlBody += "</body></html>";

 

string fileName = @"c:\temp.html"

GenerateFile(htmlBody, fileName);

Published Tuesday, July 24, 2007 10:50 PM by arpans

Comments

# SharePoint Web Service Example &ndash; Grabbing Wiki Content &laquo; CodeJedi.NET

# re: SharePoint Web Service Example – Grabbing Wiki Content

Wednesday, August 08, 2007 12:05 PM by Daniele Muscetta

very nice to see how you can extract wiki pages and info from the webservices in SP 2007....

Some time ago, I also posted some code which used the web service of sharepoint (2003):

http://blogs.msdn.com/dmuscett/archive/2005/09/27/SharePoint_Unortodox_RSS_Feed.aspx

...it has been running from the scheduler on my server for years now, generating an RSS feed from a friend's sharepoint day in day out....

web services are cool (REST web services are even cooler, tough...)

# WSS 3.0 & MOSS: Recopilación de enlaces interesantes (V)

Thursday, August 16, 2007 7:38 AM by Blog del CIIN

Después de unas semanas de vacaciones (cortas :PPP), aqui estamos de nuevo en el CIIN al pie del cañón

# 2007 MOSS Resource Links (Microsoft Office SharePoint Server)

Monday, September 17, 2007 2:53 PM by The Boiler Room - Mark Kruger, Microsoft SharePoint MVP

2007 MOSS Resource Links (Microsoft Office SharePoint Server) Here is an assortment of various 2007 Microsoft

# Using SharePoint web services to get list items

Tuesday, October 23, 2007 6:21 AM by Aidan Garnish

Using SharePoint web services to get list items

# Using SharePoint web services to get list items

Wednesday, April 16, 2008 5:53 PM by Aidan Garnish

Using SharePoint web services to get list items

New Comments to this post are disabled
 
Page view tracker