0

In SharePoint 2013, I have a document library with a folder structure. If a user is created using the form based authentication then automatically their respective folder is created in the document library using a program.

Now my requirement is, the created folder will be edited/viewed by the user who has been added to the system and other user should not able to view or edit that folder.

How to do this using program?

0

please have a look in this answere for how to do it programmatically: Problem Setting Item Level Permissions Dynamically

or this article: https://akifkamalsyed.wordpress.com/2011/04/30/how-to-progammatically-set-item-level-permissions-in-sharepoint/

The following code which come form the link above is posted if the link becomes unavailable:

public void ItemLevelPermissions(SPWeb web, SPListItem item, string userName)
 {
    try
     {
        if(!item.HasUniqueRoleAssignments){
            item.BreakRoleInheritance(false);
            SPPrincipalInfo user = SPUtility.ResolvePrincipal(web, userName, SPPrincipalType.All, SPPrincipalSource.All, null, false);
            SPRoleDefinition RoleDefinition = web.RoleDefinitions.GetByType(SPRoleType.Reader);
            SPPrincipal member = null;

            if(user.IsSharePointGroup)
                { member = web.Groups.GetByID(user.PrincipalId); }
            else
                { member = web.AllUsers.GetByID(user.PrincipalId); }

            if ((item.GetUserEffectivePermissions(userName) & SPBasePermissions.ViewListItems) == 0)
            {
                SPRoleAssignment RoleAssignment = newSPRoleAssignment(member);
                RoleAssignment.RoleDefinitionBindings.Add(RoleDefinition);
                item.RoleAssignments.Add(RoleAssignment);
            }

            item.SystemUpdate();
        }
     }
    catch (Exception ex)
     {
        ExceptionHandler.LogException(ex);
     }

}
  • Thank you sebastian.i will use this and tell you the result. – Saravanan.S Nov 6 '15 at 6: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.