I need to get the folder object, SPFolder using C# in my SP 2013 on-prem site collection.

Below code, I have created a new folder programmatically.

Now how can I get this SPFolder object and later I wanna apply Contribute permissions for this folder?

It would be good, if i can get GUID approach. There is only one param, we need to pass , thats GUID, but how to retrieve the GUID of the folder.

    SPList marketrsrchDocLib = paramCurrentWeb.Lists.TryGetList("MarketResearch");
    if (marketrsrchDocLib != null)
        listitemDivisionFolder = marketrsrchDocLib.Items.Add("", 
                                  SPFileSystemObjectType.Folder, strDivisionNameCreated);

     //now apply permissionsfor the folder -
     SPFolder folder =   paramCurrentWeb.GetFolder(???) 
     //?? what should be the correct code here

Can you try out the below sample code that I took from here - I have a online enviornment, hence couldnt try,

SPFolder folder = SharePointConfiguration.Site.GetFolder(path); //path of the folder
SPGroupCollection spc = SharePointConfiguration.Site.SiteGroups;
SPGroup group = spc[groupName]; //name of the group with the contribute permissions
SPRoleAssignment roleAssignment = new SPRoleAssignment((SPPrincipal)group);

Basically, this is taking a folder instance by path, picking up the relevant group and assigning permissions as specified.

Source : MSDN

| improve this answer | |
  • Whats the value of the path variable? – userAZLogicApps Jul 13 '17 at 11:54
  • 1
    would be in the format <sp site url>/<Library Name>/<Folder> – Swayam Siddha Jul 13 '17 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.