Paul Galvin's (old) SharePoint space [SharePoint

Just another WordPress.com site

Quick and Easy: Get the SPFolder of an SPListItem in an Event Receiver

I hate to admit it, but I struggled with this one all day.  My event receiver needs to update a field of its parent folder.  This little bit shows how to do it:

        private void UpdateParentFolder(SPItemEventProperties properties)
        {

            SPFolder thisItemFolder = properties.ListItem.File.ParentFolder;
            thisItemFolder.Item["ZZ Approval Status"] = "Good news, everyone!";
            thisItemFolder.Item.Update();
           
           
        } // UpdateParentFolder

In this case, I’m working with a document library and the properties are coming from an ItemAdded event.

The trick is that you can’t get the SPFolder of the item directly from the item itself (i.e. properties.ListItem.Folder is null).  Instead, go to the list item’s associated File and get the File’s folder.

</end>

 Subscribe to my blog!

Technorati Tags:

One response to “Quick and Easy: Get the SPFolder of an SPListItem in an Event Receiver

  1. korhan August 15, 2008 at 7:12 am

    Thank you very much.
    I was searching this code for three days.
    It\’s working.

Leave a comment