Wednesday, January 31, 2007

Synchronous List Event Properties

Some people have posted (for example here) about not being able to access the properties of a list item in a synchronous list event (e.g. ItemAdding). Maybe this was fixed in the RTM but I'm not seeing this problem - the properties are actually there - they'll show up in the AfterProperties collection, although they can sometimes be a little hard to spot. One trap to watch out for is that the keys in the hashtable correspond to the fields' internal names, so that, for example, any spaces will be encoded as "_x0020_". To be safe, it pays to use a syntax something like the following:

string myFieldValue = Convert.ToString(properties.AfterProperties[properties.ListItem.Fields["My Field Name"].InternalName]);


An example of iterating through the SPItemEventDataCollection:
public override void ItemAdding(SPItemEventProperties properties)
{
    base.ItemAdding(properties);
    foreach (DictionaryEntry dictionaryEntry in properties.AfterProperties)
    {
    }
}

Wednesday, January 17, 2007

InfoPath Forms Services close button redirection

In my installation of MOSS 2007, editing a browser-enabled InfoPath form in a document library by choosing Edit in Browser from the context menu doesn't pass the 'Source' parameter (described in a post by Scott Jamison here) in the URL to the /_layouts/formserver.aspx page. The parameter is passed correctly when creating a new form in the document library. The result of this is two different behaviors when users are finished editing the form and click the close button. If it's a new form, there is a postback and the browser redirects to the document library. If it's an existing form that is being edited, the browser doesn't redirect, instead it shows the following dialog:

The form has been closed.


I came up with a work around - editing the custom action in the IPFS file:

%PROGRAMFILES%\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\IPFSSiteFeatures\FormServerEcbEntry\EcbEntry.xml


...and changing the appropriate UrlAction elements to include a source parameter, i.e.


<UrlAction Url="~site/_layouts/formserver.aspx?XmlLocation={ItemUrl}&amp;OpenIn=Browser&amp;Source=&lt;SCRIPT&gt;document.write(escapeProperly(window.location.href))&lt;/SCRIPT&gt;"/>

It's not the best solution however (because the file will get overwritten by any updates etc.) - but I haven't seen any other answers out there.