May 2004 - Posts

If you’ve visited a SharePoint site, you’ve probably noticed the Messenger-style icons in front of people’s names corresponding the IM status. When you hover the mouse pointer over that icon a lot of additional Messenger and Outlook functionality becomes available: you can send an email to that person, plan a meeting, … Isn’t the SharePoint – Office integration great? A nice example is the Members web part:

Patrick Tisseghem showed already in a demo during the Belgian Dev&IT-Pro Days, how you can use this functionality in your own web parts. but I couldn’t find any information on the net that showed how to do this. Well in fact is quite simple to accomplish this and you can easily test this in a SharePoint site. Just drag and drop a Content Editor web part on a SharePoint site, open the tool pane and click the Source Editor button. In the text entry window type following HTML:
My presence information:<br>
<span>
<img border="0" height="12" width="12" src="/_layouts/images/blank.gif" onload="IMNRC(
'themail@address.com')" id="IMID1" ShowOfflinePawn=1>&nbsp;Jan Tielens
</span>

The result (the menu showed above pops up when you hover over the image) is:

The magic happens in the IMNRC client-side Javascript function that’s called when the OnLoad event of the image is triggered. This function can be found in the /_layouts/1033/owsbrows.js file. Make sure your put span tags around image and the text, otherwise you’ll end up with some unexpected (but funny) behaviour. Also remember that you need to generate a unique id value for each presence information block. Finally, if you don’t want the offline image to show when the user isn’t online, you can omit the ShowOffLinePawn tag.

In my previous post I described a problem I was having while implementing a generic SharePoint Document Library Event Handler. When you save a document from Office 2003 (for example Word 2003) into a SharePoint Document Library, the document item in the library is “locked for editing” as long as the Office 2003 application stays open. This can be a problem, for example when you want the Event Handler to update a field of the document item when it’s submitted to the Document Library. There are no problems when using the web interface, but when a user does this by using Office 2003 you’ll end up with the following exception:
Microsoft.SharePoint.SPException: Document Locked
The document you are attempting to edit is locked and cannot be updated.  It may be in use by another user or undergoing content indexing.

Too bad there isn’t even an event that the Event Handler can intercept when the document is un-locked (when the user closes the Office 2003 application). So I came up with following solution: you can use the CheckOutStatus property of the SPFile class to check if the document item is locked. The CheckOutStatus property can have three values:

  • LongTerm
    Specifies that the check-out is long-term.
  • None
    Specifies that the file is not checked out.
  • ShortTerm
    Specifies that the file has been opened by a user and is locked for editing. A short-term check-out, or file-locking, only has effect as long as the application renews the lock.

As long as the CheckOutStatus property is not equal to None, I suspend the thread that’s handling the event. You can do this pretty easy in a loop:

public void OnEvent(SPListEvent listEvent)
{
    SPFile file = web.GetFile(listEvent.UrlAfter);
    while(file.CheckOutStatus != SPFile.SPCheckOutStatus.None)
    {
        System.Threading.Thread.Sleep(1000);
        file = web.GetFile(le.UrlAfter);
    }
}

The second line in the while code block is needed to refresh the values of the SPFile object. I’m not completely happy with the solution, my first concern is that when the IIS Worker Process gets killed, all the event handlers that haven’t finished are lost. So the worst case scenario is that for example the IISRESET is used when an event handler is in the while loop. My second concern is scalability: when a lot of users submit a lot of documents at the same, possibly a lot of threads could be sleeping, so a lot of threads could be active which could lead to some performance issues. Well for now I can live with these concerns, just keep in mind when you use this approach what the consequences are. In my opinion, the cleanest solution would be that SharePoint only raised events when the document is un-locked...

More Posts « Previous page