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 https://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 = "https://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=\"" + "https://faq/sites/sharepoint/wiki pages/"+ wikiName + "\">" + wikiName + "</a><br>"; htmlBody += wikiBody; } } } }
htmlBody += "</body></html>";
string fileName = @"c:\temp.html" GenerateFile(htmlBody, fileName); … |
Comments
- Anonymous
July 25, 2007
PingBack from http://wcornwill.wordpress.com/2007/07/26/sharepoint-web-service-example-grabbing-wiki-content/ - Anonymous
August 08, 2007
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...) - Anonymous
August 15, 2007
Después de unas semanas de vacaciones (cortas :PPP), aqui estamos de nuevo en el CIIN al pie del cañón - Anonymous
September 17, 2007
2007 MOSS Resource Links (Microsoft Office SharePoint Server) Here is an assortment of various 2007 Microsoft - Anonymous
October 22, 2007
Using SharePoint web services to get list items - Anonymous
April 16, 2008
Using SharePoint web services to get list items - Anonymous
June 17, 2009
One of the key things you’ll likely want to do with SharePoint is interact a lot with lists. In earlier