How to get GUID of a subfolder in a document library programmatically
Okay, here is the scenario... I have created a subfolder in a document library, and when an item开发者_如何转开发 is added to the document library, i want to do some processing on the document and then move the item to the subfolder, say MySubFolder. For that purpose, i will be using this statement
SPListItem folder = this.workflowProperties.List.Folders[];
but the Folders[] collection will take either an int index or a guid. SInce i am doing it in a workflow, I dont know how to get the guid of the folder here. Please note that I cannot use the url to get the GUID here because the same workflow is applied to a number of document libraries and I have the MySubFolder subfolder in all of them, so giving the url seems a bit tacky here i think.
I don't have Sharepoint here right now, but you should be able to do:
Guid folderId = Guid.Empty;
foreach (SPFolderCollection folder in YourList.Folders)
{
if (folder.Name == "MySubFolder")
{
folderId = folder.UniqueId;
break;
}
}
Or, into your event handler, build your folder URL:
public override void ItemDeleting(SPItemEventProperties properties)
{
Uri folderAddress = new Uri(properties.BeforeUrl, "MySubFolder");
SPFolder folder = yourWeb.GetFolder(folderAddress.ToString());
}
I solved it by doing the following:
Guid folderId = Guid.Empty;
SPFolder spFolder = web.Folders[this.workflowProperties.List.Title].SubFolders["MySubFolder"];
folderId=spFolder.UniqueId;
精彩评论