locked
Finding Folder Name RRS feed

  • Question

  • Hi All,

    I have a problem. I have written a eventhandler which fires on itemupdated. Now in my document library there are few folders. Now I am going inside a folder and uploading a document there and on its itemupdated event I need to know under which folder the document is saved ( as the folder name is a metadata). HOw to get this folder name? ... I tried SPContext.Current.ListItem.Folder but its not working .. (Object reference not found error) ....

    Plz tell if u have any solution

    Thanks
    Wednesday, August 20, 2008 5:28 PM

Answers

  • You should be able to use something like this in your event handler

    SPListItem item = properties.ListItem;  
    SPFolder folder = item.File.ParentFolder;  
    String folderName = folder.Name; 

    I hope that helps. Keep in mind though that you will only get the updated list item in the ItemUpdated event, in ItemUpdating whatever the changes that the user has made won't be in the SPListItem yet.
    Brian Farnhill
    Microsoft Certified Professional
    http://pointstoshare.spaces.live.com
    • Proposed as answer by Madhur Ahuja Thursday, August 21, 2008 7:47 AM
    • Marked as answer by Paul Galvin Thursday, August 21, 2008 1:53 PM
    Wednesday, August 20, 2008 8:55 PM

All replies

  • You should be able to use something like this in your event handler

    SPListItem item = properties.ListItem;  
    SPFolder folder = item.File.ParentFolder;  
    String folderName = folder.Name; 

    I hope that helps. Keep in mind though that you will only get the updated list item in the ItemUpdated event, in ItemUpdating whatever the changes that the user has made won't be in the SPListItem yet.
    Brian Farnhill
    Microsoft Certified Professional
    http://pointstoshare.spaces.live.com
    • Proposed as answer by Madhur Ahuja Thursday, August 21, 2008 7:47 AM
    • Marked as answer by Paul Galvin Thursday, August 21, 2008 1:53 PM
    Wednesday, August 20, 2008 8:55 PM
  • THANKS BRIAN ..... it was a great help ! ...
    Now its working fine ....
    Thanks once again
    Thursday, August 21, 2008 4:25 AM