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!
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