El Blanco's Office 2007 Blog

Monday, March 17, 2008

You Can’t Remove an Item from the SPPropertyBag

Hopefully as most of us know by now, the SPWeb class has a property called "Properties" which returns an object of type SPPropertyBag. This is effectively a class sub-classed from the StringDictionary class, and the collection is persisted in the SharePoint content database making it an ideal location to store any custom web-based properties you need to persist.

To store something in the property bag for a web is very easy indeed:

SPWeb web = . . . .
web.Properties.Add("some key", "some value");

This will store a new key-and-value pair in the StringDictionary and then persist the StringDictionary to the SharePoint content database.

You can retrieve the stored value as follows:

String storedValue = web.Properties["some key"];

The problem I've encountered is that it is not possible to remove this key-and-value pair from the StringDictionary. One would expect the following code to perform this action, but it doesn't work.

web.Properties.Remove("some key");

If you debug this code and interrogate the StringDictionary after the call to the Remove() method, then you will see that the key-and-value pair has indeed been removed, however for some reason it looks as if the call to the Update() method does not handle the removal correctly as this change is not persisted to the content database.

Anyone found a solution for this ??!

Tuesday, March 11, 2008

TFS Source Control Comparisons and Whitespace

Not a usual post about SharePoint or Office, but something that I hope may help some people who find the same issue I did with TFS. I found a problem today with Team Foundation Server (TFS) when trying to compare some changes I had made against the latest version held within source control – by default it appears as if TFS uses diffmerge.exe and passes the /ignorespace option which means that changes that consist solely of whitespace are ignored and the files are deemed to be identical.

Consider the following example where you have a source file in TFS containing the following line of code:

String example = "this is an example string";

You then check out the file and edited the file to add extra whitespace at the start of the string as shown below:

String example = " this is an example string";

Within TFS, if you do a comparison of the file, TFS tells you that the file is identical to the latest version that is checked in on the TFS server. Clearly this is not the case, and it due to the fact that by default TFS passes the /ignorespace option to the diffmerge.exe tool it uses to compare files.

To solve this issue follow the steps below to specify a custom tool to use for comparing files (note, we're still going to use the standard diffmerge.exe tool, but we're not going to specify the /ignorespace option):

  1. Within VS.NET 2005 select the "Tools -> Options" menu item.
  2. Expand the "Source Control" node and select "Visual Studio Team Foundation Server".
  3. Click the "Configure User Tools…" button then click the "Add" button to add a new tool.
  4. Configure the settings for the tool to be the following:
    1. Extension: set this to be ".*" i.e. dot star.
    2. Operation: ensure this is set to "Compare".
    3. Command: set this to be "C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\diffmerge.exe" which is the default path to the diffmerge.exe tool.
    4. Arguments: leave this as standard i.e. leave this as "%1 %2".
  5. Click OK all the way back up the dialog hierarchy to save the settings.

If you now compare the file that we previously modified and added the whitespace to, TFS will correctly show that the files differ on the modified line of code.

Another Bug with a CustomAction in the Actions Menu

I have found another bug with a CustomAction element which adds an item to the Actions menu on a document library:

<CustomAction Id="SomeCustomAction"
Title="Some Custom Action"
Description="Does something interesting.">
<UrlAction Url=""/>

The new menu item defined above appears in the Actions menu for document libraries, and it appears as the last item in the menu, right at the very bottom.

My issue is that I can't seem to get the menu item to be present anywhere but at the bottom i.e. what if I wanted the menu item to appear as the first item in the Actions menu? I've set the Sequence attribute to various different values, but this appears to have no effect - so far I've not managed to change the positioning of the new menu item and it always appears at the bottom of the Actions menu.

Has anyone else created a CustomAction for the Actions menu and managed to get it to be positioned elsewhere in the menu? If so, please get in touch !!