views:

575

answers:

2

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.

A: 

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());
}
Rubens Farias
Thanks a lot for your code, I was receiving an error saying YourList.Folder returns SPListItems and it couldnt b cast as SPFolderCollection.But your solution definitely put me on the right track and i found the solution below:) thanks
ria
A: 

I solved it by doing the following:

Guid folderId = Guid.Empty;
SPFolder spFolder = web.Folders[this.workflowProperties.List.Title].SubFolders["MySubFolder"];
folderId=spFolder.UniqueId;
ria