2010, c# server object model

I'm trying to programmatically assign permissions to specific folders in a document library (see my original post here) but I'm hung up on selecting a folder as an SPListItem. In the past I've always used SPFolder to create and manipulate folders, but I can't figure out how to cast that as an SPListItem which is necessary for permission editing. Any insight or even just links to articles are appreciated!

Edit: The SPFolder.Item property is what I'm looking for, but I've run into a new problem trying to use it. I'm picking the folder by building a string for its Url and then calling the GetFolder method on the SPWeb. When I then call the .Item property on it, I get the exception "The object specified does not belong to a list." I'm guessing that's because I called it off the SPWeb and not an SPList, but I don't know another way to select that specific folder. See the code below for an example.

string fullPath = parentFolder + projectFolder + phase1Folder; // This is a dynamically generated Url
//For example, "site/web/Document Library 1/Project Name/Phase 1"
SPFolder oFolder = oWeb.GetFolder(fullPath);
SPListItem oItem = oFolder.Item; // This is where the exception is thrown
  • 3
    Doesn't SPFolder.Item return you the SPListItem assocaited with the folder. Can you share your code? Aug 9, 2013 at 17:05
  • You can have folder out of list or library, for example web.RootFolder.
    – dbardakov
    Mar 31, 2015 at 10:43
  • In my case it was caused by invalid path for GetFolder method - I've had a space included in the path (which unexpectedly didn't cause SPFolder itself to throw exception) May 5, 2017 at 0:16

1 Answer 1


Use the SPFolder.Item property. A generic example:

foreach (SPFolder folder in collFolders)
  SPListItem item = folder.Item
  • That's probably what I'm looking for, however I'm having trouble calling the .Item property on it due to the way I'm selecting the folder to begin with. See my edit above.
    – thanby
    Aug 12, 2013 at 18:22
  • try getting the relative path to the folder instead of the full path...starting after the web.
    – BlueBird
    Aug 13, 2013 at 13:09

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.