SharePoint Blog - René Hézser

Anmelden  RSS Feed RSS Feed
Startet die Suche

Archive

Kategorien

Links

Andere Blogs




ITaCS GmbH


Implement an update check  

Aug 272008

You have developed a Webpart or some other program, and want the user to be able to check for updates?

In my case I want the user to check for updates for my Webparts.

If you click the "Check for updates" Button in the Webpart properties, the latest version from will be shown.

 

 

Set up an "Updates" list

To find the latest version, I have set up a SharePoint list with two fields. The title always exists. I renamed it to be "Assembly". The second column we need is the version. Here I store values which can be interpreted as a Version object.

This list has to be accessible for anonymous users. But how do we ask for the items in this list from "outside". My first thought was a webservice. SharePoint has its own build-in webservice. So let's just use the lists.asmx webservice, and get the item for our assembly.

Access the list from the internet

The problem is that the webservice cannot be used as an anonymous user. That is a shame. Because the items can be read by anonymous users without authentication (guess that is the most important point to anonymous users…).

So we write our own webservice. Or we can use the RSS feed from our updates list. This way we will not have to write a webservice, but can access the data anonymously from the internet.

Enable RSS

When we enable the RSS feed for our update list, we just check the "VersionNr" field to be included. The title will be included anyway. We will use a DataTable with ReadXml:

   1: public class Updates
   2: {
   3:     private readonly string _Assembly;
   4:     private readonly string _FeedUrl;
   5:     private string _ErrorText;
   6:  
   7:     /// <summary>
   8:     /// create updates class with an assemblyname
   9:     /// </summary>
  10:     /// <param name="assembly"></param>
  11:     public Updates(string assembly)
  12:     {
  13:         _Assembly = assembly;
  14:         _FeedUrl = "yourfeedurl";
  15:     }
  16:  
  17:     public Updates(string Assembly, string FeedUrl)
  18:     {
  19:         _Assembly = Assembly;
  20:         _FeedUrl = FeedUrl;
  21:     }
  22:  
  23:     /// <summary>
  24:     /// find lates version from rss feed
  25:     /// </summary>
  26:     /// <returns></returns>
  27:     public LatestVersion GetLatestVersion()
  28:     {
  29:         try
  30:         {
  31:             var ds = new DataSet();
  32:             ds.ReadXml(_FeedUrl, XmlReadMode.Auto);
  33:  
  34:             DataTable dt = ds.Tables["item"];
  35:             foreach (DataRow row in dt.Rows)
  36:             {
  37:                 if (Convert.ToString(row["title"]) != _Assembly) continue;
  38:  
  39:                 // we found our assembly
  40:                 string description = Convert.ToString(row["description"]);
  41:                 DateTime publishDate = Convert.ToDateTime(row["pubDate"]);
  42:  
  43:                 return new LatestVersion(description, publishDate, _ErrorText);
  44:             }
  45:             return new LatestVersion("No Versioninformation found.");
  46:         }
  47:         catch (Exception ex)
  48:         {
  49:             return new LatestVersion(ex.Message);
  50:         }
  51:     }
  52: }
 
The version is in the "description" column in our DataTable.
To get the latest version, we create an instance of the Updates class and call the GetLatestVersion function.
   1: var latest = new Updates("RH.MyAlerts");
   2: LatestVersion latestVersion = latest.GetLatestVersion();
 
That's it.

Tags:

 
Posted by René Hézser | 0  Comments | Trackback Url  | 0  Links to this post | Bookmark this post with:        
Tags: Development, SharePoint
Technorati Tags: ,

Links to this post

Comments

Name *:
URL:
Email:
Kommentar:


CAPTCHA Image Validation