Friday, January 7, 2011

List event handlers issue in datasheet view in MOSS

Hi,

After struggling a lot with MOSS document library event handlers I found some solution on it.

Scenario: - I need to update file name property using event handler but not from standard view of document library but from the datasheet view of it. Always getting the resolve link with some error on the view.

Solution: Finally I got the solution for this known issue (MS) in MOSS. Below is some sample code for the same.

public override void ItemUpdated(SPItemEventProperties properties)
{
try
{
this.DisableEventFiring();
string fileName = properties.AfterUrl;
fileName = fileName.Split('/')[1].ToString();
SPList list;
SPListItem item;
list = properties.ListItem.ParentList;
item = list.GetItemById(properties.ListItemId);
if (!Convert.ToString(item["Filename"]).Equals(fileName))
{
item["Filename"] = fileName;
item.SystemUpdate(false);
}
this.EnableEventFiring();
}
catch (Exception ex)
{
}
finally
{
this.EnableEventFiring();
}
base.ItemUpdated(properties);
}

Hope it will help a lot of guys we need it badly like me.