1

I have an ItemAdded event receiver that is exporting files as they are added to a list. In my event receiver I want to find the containing folder of the item. This folder may be a SPFolder object or could be the top level list. Is there a clean way of getting this information without parsing the item.File.Url.

pstrjds
  • 221
  • 4
  • 13

1 Answers1

3

Try using this in your ItemAdded method:

SPFile file = properties.ListItem.Web.GetFile(properties.ListItem.Url);
SPFolder fileFolder = file.ParentFolder;

If the file is in the root of the list then file.ParentFolder will return an SPFolder that represents the list itself.

Hope that helps.