Getting jiggy with RPCs

Recently there were a few articles flying around discussing the Windows SharePoint Services RPC methods and things you can do with them. I thought I would do up some short demos using nothing but XML, XSLT and the built-in SharePoint Web Parts. You can do this as well and create your own pseudo-Web Parts with no coding! Neat huh?

First off, the RPC methods have two things going for them. They're very powerful and very difficult to sometimes get to do what you want them to do. The great thing however is that for most of them, they return either an ADO.NET RecordSet (which we'll see how to get information out of) or just regular XML responses that you can easily use to put into a Web Part.

The Basics
Using the Url protocol, you can call these from a simple PageViewer Web Part or put the results into the Xml Web Part. The Url needs to be formatted a certain way:

http://Server_Name/[sites/][Site_Name/]_vti_bin/owssvr.dll?Cmd=Method_name[&Parameter1=Value1&Parameter2=Value2

It's really not that hard. The Method name is whatever method you want to call (not all methods are available via the Url protocol). The following methods are:

  • dialogview - Opens a view of the document libraries within a site, of a specific document library, or of a folder within a document library that is used in a dialog box for opening or saving files; or opens the property form that is used when saving a file.
  • Display - Runs a database query against the list specified by a GUID and returns XML or HTML.
  • ExportList - Exports in CAML format the schema of the list specified by a GUID.
  • GetProjSchema - Requests the XML Schema for a Web site.
  • GetUsageBlob - Returns information about the usage of a Web site.
  • HitCounter - Generates a hit on a page containing a hit counter.
  • RenderView - Requests the contents of a view for the list specified by a GUID.

We're only going to look at a couple here, but feel free to experiment on your own.

Display
For this sample, I've setup a document library called "Samples" on my site and we'll use the Display RPC Method to get the data from it:

http://sharepoint.bilsimser.com/_vti_bin/owssvr.dll?Cmd=Display&List={40A74BD8-9263-4041-8894-F25A4D59D608}&XMLDATA=TRUE

The List parameter needs a GUID for the list. You can get this when you select your list and click on Modify Settings and Columns. The GUID is displayed in the Address to the page in your browser. Just copy and paste it for your own list. Click on that link in your browser and you'll see something like this:

- <xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
- <s:Schema id="RowsetSchema">
- <s:ElementType name="row" content="eltOnly" rs:CommandTimeout="30">
- <s:AttributeType name="ows_DocIcon" rs:name="Type" rs:number="1">
  <s:datatype dt:type="string" dt:maxLength="512" />
  </s:AttributeType>
- <s:AttributeType name="ows_LinkFilename" rs:name="Name" rs:number="2">
  <s:datatype dt:type="string" dt:maxLength="512" />
  </s:AttributeType>
- <s:AttributeType name="ows_Last_x0020_Modified" rs:name="Modified" rs:number="3">
  <s:datatype dt:type="datetime" dt:lookup="true" dt:maxLength="16" />
  </s:AttributeType>
- <s:AttributeType name="ows_Editor" rs:name="Modified By" rs:number="4">
  <s:datatype dt:type="string" dt:lookup="true" dt:maxLength="512" />
  </s:AttributeType>
- <s:AttributeType name="ows_LinkCheckedOutTitle" rs:name="Checked Out To" rs:number="5">
  <s:datatype dt:type="string" dt:maxLength="512" />
  </s:AttributeType>
  </s:ElementType>
  </s:Schema>
- <rs:data>
  <z:row ows_DocIcon="doc" ows_LinkFilename="01_HighConceptPrimer.doc" ows_Last_x0020_Modified="1;#2006-01-03 19:03:13" ows_Editor="1;#Bil Simser" />
  <z:row ows_DocIcon="doc" ows_LinkFilename="01_HighConceptTemplate.doc" ows_Last_x0020_Modified="2;#2006-01-03 19:03:13" ows_Editor="1;#Bil Simser" />
  <z:row ows_DocIcon="doc" ows_LinkFilename="02_PrelimGameDesignPrimer.doc" ows_Last_x0020_Modified="3;#2006-01-03 19:03:13" ows_Editor="1;#Bil Simser" />
  <z:row ows_DocIcon="doc" ows_LinkFilename="02_PrelimGameDesignTemplate.doc" ows_Last_x0020_Modified="4;#2006-01-03 19:03:13" ows_Editor="1;#Bil Simser" />
  <z:row ows_DocIcon="doc" ows_LinkFilename="03_RoadMap.doc" ows_Last_x0020_Modified="5;#2006-01-03 19:03:13" ows_Editor="1;#Bil Simser" />
  <z:row ows_DocIcon="doc" ows_LinkFilename="04_RequirementsPrimer.doc" ows_Last_x0020_Modified="6;#2006-01-03 19:03:13" ows_Editor="1;#Bil Simser" />
  <z:row ows_DocIcon="doc" ows_LinkFilename="05_FinalGameDesignPrimer.doc" ows_Last_x0020_Modified="7;#2006-01-03 19:03:13" ows_Editor="1;#Bil Simser" />
  <z:row ows_DocIcon="doc" ows_LinkFilename="05_FinalGameDesignTemplate.doc" ows_Last_x0020_Modified="8;#2006-01-03 19:03:13" ows_Editor="1;#Bil Simser" />
  <z:row ows_DocIcon="doc" ows_LinkFilename="06_TechDesignPrimer.doc" ows_Last_x0020_Modified="9;#2006-01-03 19:03:14" ows_Editor="1;#Bil Simser" />
  <z:row ows_DocIcon="doc" ows_LinkFilename="07_PublisherMilestonesDeliverables.doc" ows_Last_x0020_Modified="10;#2006-01-03 19:03:14" ows_Editor="1;#Bil Simser" />
  <z:row ows_DocIcon="doc" ows_LinkFilename="09_BugReporting.doc" ows_Last_x0020_Modified="11;#2006-01-03 19:03:14" ows_Editor="1;#Bil Simser" />
  <z:row ows_DocIcon="doc" ows_LinkFilename="09_GameTestingMethodology.doc" ows_Last_x0020_Modified="12;#2006-01-03 19:03:14" ows_Editor="1;#Bil Simser" />
  <z:row ows_DocIcon="doc" ows_LinkFilename="09_GameTestingPrimer.doc" ows_Last_x0020_Modified="13;#2006-01-03 19:03:14" ows_Editor="1;#Bil Simser" />
  <z:row ows_DocIcon="doc" ows_LinkFilename="09_TestDesignGuideline.doc" ows_Last_x0020_Modified="14;#2006-01-03 19:03:14" ows_Editor="1;#Bil Simser" />
  </rs:data>
  </xml>

This is the Xml that came back from our list and is basically an ADO.NET RecordSet. Nice. Now we want to do something with it. 

Drop an Xml Web Part onto a page and enter the Url for your own list into the Xml Link field. Now we want to format this so we can use a simple Xsl file to format the output. In this case, I'm going to put the results into a table. Here's the Xsl file you can enter into the Xsl Editor:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:z="#RowsetSchema" xmlns:rs="urn:schemas-microsoft-com:rowset">
<xsl:output method="xml" />

<xsl:template match="/">
<table border="1">
        <xsl:apply-templates select="/xml/rs:data"/>
</table>
</xsl:template>

<xsl:template match="z:row">
<tr>
<td><xsl:value-of select="@ows_DocIcon"/></td>
<td><xsl:value-of select="@ows_LinkFilename"/></td>
<td><xsl:value-of select="@ows_Last_x0020_Modified"/></td>
<td><xsl:value-of select="@ows_Editor"/></td>
</tr>
</xsl:template>

</xsl:stylesheet>

It's really simple and just selects all the items in the list and displays them in a table. You can see the final output here on this page. That's just a simple example but lets you really grab information from SharePoint without having to resort to building Web Parts. With some transformation you can change the way the information is displayed (for example formatting the dates). You can accomplish the same using the DataView Web Part if you want to use FrontPage, but this method works just as well (although it does require an understanding of Xml/Xsl so be ready to learn something new).

Online ONET.XML
This method is one of my favs as it basically lets you see everything about your site, online. The RPC Method, GetProjSchema, will return you something very similiar to what you would see if you opened up an ONET.XML file for a site. Site Name, Navigation Bars, Document Templates, Modules, etc. It's not exactly the same, but is coming straight from the source and with it you can do some pretty cool stuff.

First, go ahead and invoke it on my demo site. Here's the Url:

http://sharepoint.bilsimser.com/_vti_bin/owssvr.dll?Cmd=GetProjSchema

This brings back the output which is just Xml. It starts with the Project tag, then continues on with NavBars, ListTemplates, DocumentTemplates, BaseTypes, Configurations, and finally Modules. Yup, just like ONET.XML.

What can we do with this information? Well, let's say we want to show a list of all the available Templates on the site with a description (very much the same as what you get when you look at the Create Page). Create a new Xml Web Part, hook it up to call the GetProjSchema method on your site (or mine, I don't much care) and enter this into the Xsl Editor:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:z="#RowsetSchema" xmlns:rs="urn:schemas-microsoft-com:rowset">
<xsl:output method="xml" />

<xsl:template match="//Project">

<table border="1">
<tr>
<td><strong>Template Name</strong></td>
<td><strong>Description</strong></td>
</tr>
<xsl:for-each select="/Project/ListTemplates/ListTemplate">
<tr>
<td><xsl:value-of select="@DisplayName"/></td>
<td><xsl:value-of select="@Description"/></td>
</tr>
</xsl:for-each>
</table>

</xsl:template>

</xsl:stylesheet>

Great. You now have a table that lists all the templates in your site with a description. Here's what the sample output looks like. You can extend this to do things like building your own Create page (filtering things out you don't want). You're really only limited by your imagination (and some XSLT skills). Just remember that you can only manipulate the information that you get from the queries, but if you're skilled at XSLT you can do things like combine requests and pull in various pieces of the system together to do your bidding (even have one Xml Web Part feed another).

So check out the MSDN documentation on the RPC methods and have fun! 

4 Comments

  • Great article, especially the short demos!

  • Looks great Bil! I am looking forward to getting my hands on the end result. Think you will have it done before the 2006 SharePoint Connections conference in April? I have a discussion section on my Helpdesk solution presentation and I would like to show your Web Part instead of the OOTB Web Part.



    Bob Mixon

  • Hi,
    look, I'm trying the first way of displaying XML data. I'm getting this error in the web part: "Cannot retrieve the URL specified in the XML Link property. For more assistance, contact your site administrator."
    I've seen that several people have got this issue. Any ideas?
    Thanks everyone.

  • This doesn't seem to work the same way anymore in SharePoint 2010. First, you'll need to adjust the URL to point to the specific site to get past the error BUT it does not return the same data. If I find a fix, I'll post.

Comments have been disabled for this content.