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.

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.