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