Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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