SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Given the following information;

string webUrl, Guid listId, int itemIdInList

I'm trying to retrieve the parent of this item, whether that is a List or another ListItem (i.e. a folder).

Can anyone provide some guidance on how to achieve this? The list part isn't too bad, but there isn't much information online regarding the retrieval of parent folder IDs.

share|improve this question

C. McAtackney,

What you can do is make SPQuery object for querying list items and

 query.ViewAttributes = "Scope=\"Recursive\"";

Once you get list items, you can get the folder path from list item url. SPUtility.GetUrlDirectory will give you the URL directory, which consists of the folder hierarchy. Using this information you can retrieve the parent folder.

string dirPath = SPUtility.GetUrlDirectory(item.Url);  
 if (dirPath != null)  
     string[] dirs = dirPath.Split(new char[] { '/' });  
     if (dirs.Length > 0)  
       return (dirs[dirs.Length - 1]);  

And if you want to see whether the current Item is itself a Folder Content Type or a List Item, you can do something like this:

if (lstItem.ContentTypeId == SPBuiltInContentTypeId.Folder)
if (lstItem.ContentTypeId == SPBuiltInContentTypeId.Item)

I hope this helps

share|improve this answer
Hi @Arsalan, thanks for your response. I'm using the Client Object Model, so I don't believe I have access to SPUtility - is that correct? – C.McAtackney Oct 16 '12 at 10:00
Yes, you will not have SPUtility in Client OM.. Sorry, I didn't read that! – Arsalan Adam Khatri Oct 16 '12 at 10:38
@ArsalanAdamKhatri, helped me though :-) – Brian Scott Dec 27 '12 at 16:39
Good to know :-) – Arsalan Adam Khatri Dec 29 '12 at 6:44

Your Answer


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.