Welcome to MSDN Blogs Sign in | Join | Help

Using SharePoint WebService to generate a RSS Feed

This small progran is born to scratch a personal itch (like many others).
Before you read on, you HAVE to be warned that it is nowhere close to being "production quality" code, but it *just* works for me.
As you will see I am a TERRIBLE coder - I am mostly self-taught, and I DO NOT CODE FOR WORK - I mainly come from an IT Pro / System management background.
Also for this reason though, if you feel like giving (constructive) comments and criticism, or maybe even HELP OUT to clean this code, please feel free to comment here on the blog or drop me a line.
The purpose of the program is to be used as an example: it shows an approach, a technique that can be used for the problem at hand.
But which problem was it ?
I started using Sharepoint Portal Server to host a photoblog, but it did not natively support RSS to see when new photos were added. So it sounded more as a standard site than as a "blog" thing to me. It was nice an easy to edit and post photos and other things to it, but it did not feel "blog" enough due to the lack of RSS.
Searching on the web I did find some nice RSS Feed generator for Sharepoint, in the form of "web parts".
Which is ok for performance: they have te database very close, they can extract all of the IDs and the other interesting fields from lists, and re-publish those lists as RSS. Which works obviously great.
But the problem I encountered with those is that you basically need to have your own server to INSTALL them and configure IIS for them first, to be able to use them.
Or you would have to wait until when Sharepoint (next version, in the makings -  http://radio.weblogs.com/0001011/2005/09/17.html#a11176 ) will provide RSS out-of-the-box.
Yep, now it has been announced, but when I started feeling that this feature was lacking, nobody knew SharePoint would eventually get out-of-the-box-feeds, sooner or later.
Anyway, so far we are on the old version, I am in a situation where I couldn't "ADD" this functionality to it, even though I wanted it BADLY, as I am an RSS addict.
I did not have control on the Sharepoint I used, I couldn't install parts or modify it in any way - it is hosted and managed by someone else.


So I decided to make this quick and dirty hack to provide myself the functionality I wanted *without* having to do anything on the server itself.

This pet project passed thorugh several phases:
The first version of this was a VBScript based on WinHttp, which was parsing the HTML output remotely. That was REALLY ugly. It worked for ONE site, but it needed MAJOR readjusting to be used for another.
The intermediate version was also ugly, but with an attitude:
In fact it already referenced the WEBSERVICE for the Sharepoint site I mean to use, and it used it to retrieve the list of items I am interested in.
At this point it uses the information in the list to build the RSS feed, as output. The idea was there, but it was REALLY badly coded, there was a lot of hardcoded things (which forced you to recompile it to use a different site, or even a different list), and it used STRING functions to extract STUFF out of the XML the webserver gave you. HOW BAD!! HOW UGLY!! Still, it worked pretty well for what it had to do, but I wasn't happy with it.

So I went to a major rewrite of it, and this version changes a lot of things:
- it abandonds VB.NET in favour of C#;
- as a side-effect of the language change, it now works on MONO (http://www.go-mono.com) - thus not only on the MS .NET Framework - I tested it with success on mono version 1.1.8, with the only exception NOT tested being the code that handles the PROXY usage, which relies on Internet Explorer settings (GetDefaultProxy), so I doubt it will work. But I got it compiled on WIndows XP SP2 with Visual Studio 2003, just copied the executables to my Debian Linux box.... et voila'... it runs. I am running it from there without issues so far;
- it parses command line parameters (thanks to Mike Ellison for the CommandLineParser.cs code - http://www.codeproject.com/csharp/CpCommandLineEmailer.asp);
- it is indipendent from a single Sharepoint site: the way I build the reference to the webservice (allowing it to be replaced by a variable) is a dirty hack, but it should work for all Sharepoint sites of the ssame versions (I don't do the wsdl stuff properly, but can "point" to different sites using the same software and same webservice version... I don't have infinnite SharePoint sites to test this against, but I've tried a bunch of them without problems);
- it Can both enumerate lists on a given site, or the elements for a give list (and build a feed for it in the latter case);
- you can enable/disable the use of proxy (again, it relies on Internet Explorer Settings);
- it actually uses the proper XML handling classes and stuff and does not rely on string functions anymore;
- I am not crafting my output feed manually anymore as I was, I rather leveraged other people's work and adopte a "proper" RSS-generation library (RSS.NET - http://rss-net.sourceforge.net/);

 


So, how does it work ?
I provide the Visual Studio project, so full source code (or it wouldn't be useful as an example!).
You can run the executable in any DOS (CMD) box, and it will tell you its command line switches and some usage information:

  SURFCLI [-server:URL] [-list:List] [-proxy:YES] [-debug:YES]
          [-proxyuser:DOMAIN\username ||
user@domain.dom] [-proxypass:password]

for example a typical command line would be the following:

SURFCLI -server:http://www.mysite.com/sharepointsite -list:PHOTOS -limit:20

this will output the RSS to console, so in the DOS box.
To save it on a file you can simply pipe it to it:

SURFCLI -server:http://www.mysite.com/sharepointsite -list:PHOTOS -limit:20 >c:\directory\RSSFeed.xml

And this is an example of the feed you get:

(By the way, the above feed, you could look at it yourself, you can find it at http://www.muscetta.org/rss/RSSMuscettaWinIsp.xml).

 

Most command line switches are self-describing (like the proxy usage), with the exclusion (maybe) of the "-debug" switch, which will print some seemingly meaningless information (that is, debugging...) like the Xml returned from the webservice (uninterpreted), the list of fields, etc. Everything BUT a feed, anyway. This info is only useful if you are trying to figure out why a certain list gives you strage results (hey, I could not test everything!), but you won't use it normally.
Shorty, the "-debug" switch will NOT output a feed, but some garbage containing the fields which should have gone into the feed.
So you probably won't normally need to worry about it at all.

 


Why didn't I use the SharePoint object module ? Simple.... again, this is NOT meant to be running ON the sharepoint machine, otherwise it would have been nice and easy.

There are several examples of this other technique on the web (for example http://weblogs.asp.net/jan/archive/2004/04/16/114488.aspx), and it DOES make sense doing it that way if you are generating the feed locally at the server, and you can operate on it.
This is another "gateway" or "converter" approach. Since it is unconventional, I dubbed it "unortodox", and came up with a name of "S.U.R.F." (Sharepoint Un-ortodox RSS Feed).

 

What is still missing and could improved ?
Simple Answer: A lot of things.
Detailed Answer, or a list of what I think should be addressed (but I haven't got time to do it right now):
- Better input filtering to avoid security issues (I have not paid a lot of attention to it, I have to be honest);
- Better error handling and especially a more consistent one thorugh the program (maybe incorporating all errors in the "debug" switch/routines);
- Adding an "-outputfile" or similar switch, to let the program WRITE the feed instead of piping from console, to avoid messing up the generated feed... which gets written to console now;
- Fix the proxy code not to rely on Internet Explorer Settings, so that it would also work on MONO;
- test it with https (currently only http is the tested protocol) - it should make no difference, but I am afraid "http://" is hardcoded somewhere. I just did not bother doing this as my sharepoint were not using SSL. This should be easy to change, you need to manipulate the strings differently;
- This is currently limited to lists which are "photo collections" or albums... thus a thumbnail of the pic is included.... should be made more generic so that it can support other lists (it already does, just the output is strange in that case);
- could xsl transforms be used to convert from one XML format to another ? maybe.
- some comments in the code are in Italian - bear with me, many others are in english on the contrary :-)

...and possibly so much more!
But again, if you want to improve it, please feel free to help me :-)

Oh! I was nearly forgetting one important bit of information: where the code actually IS...
and here we go: it's attached to this post.

 


References:
http://www.microsoft.com/sharepoint/server/downloads/tools/SDK.asp
http://rss-net.sourceforge.net/
http://weblogs.asp.net/jan/archive/2004/04/16/114488.aspx
http://www.codeproject.com/csharp/CpCommandLineEmailer.asp



Disclaimer:
The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my own personal opinion. Inappropriate comments will be deleted at the authors discretion. All code samples are provided "AS IS" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
THIS WORK IS NOT ENDORSED AND NOT EVEN CHECKED, AUTHORIZED, SCRUTINIZED NOR APPROVED BY MY EMPLOYER, AND IT ONLY REPRESENT SOMETHING WHICH I'VE DONE IN MY FREE TIME. NO GUARANTEE WHATSOEVER IS GIVEN ON THIS. THE AUTHOR SHALL NOT BE MADE RESPONSIBLE FOR ANY DAMAGE YOU MIGHT INCUR WHEN USING THIS PROGRAM.

 

Published Tuesday, September 27, 2005 9:41 AM by dmuscett
Attachment(s): SURFCLI_CSharp_v1.2_BIN.zip

Comments

No Comments
New Comments to this post are disabled
 
Page view tracker