Set file level permissions in SharePoint using Workflow Foundation

By Geert van der Cruijsen at February 18, 2009 15:23
Filed Under: SharePoint

Hello Everyone, 

On my current project we are building a customer facing SharePoint application which has to store files. These files are uploaded with biztalk so we have to set the permissions manually so only the user who the file belongs to has rights to open te file.

We are storing the username of the owner of the file in the metadata of the sharepoint item and we are going to use this to set the permissions after the file is uploaded to sharepoint by Biztalk.

After adding the file we've set up a SharePoint Workflow to move the files to a specific location and we've come up with the idea to also change the permissions in this workflow. How we did this? here's the code to change the permissions of a SharePoint SPItem in the workflow:

   1:  workflowProperties.Item.BreakRoleInheritance(false);
   2:   
   3:  workflowProperties.Item.File.MoveTo(currentFolder + "/" + workflowProperties.Item.File.Name);
   4:   
   5:  SPRoleDefinitionCollection rolecollection = web.RoleDefinitions;
   6:  SPRoleAssignmentCollection roleAssignments = workflowProperties.Item.RoleAssignments;
   7:   
   8:  SPUser user = web.EnsureUser("aspnetsqlmembershipprovider:"+workflowProperties.Item.Properties["Username"].ToString());
   9:  SPRoleAssignment roleAssignment = new SPRoleAssignment(user as SPPrincipal);
  10:  SPRoleDefinitionBindingCollection roleDefBindings = roleAssignment.RoleDefinitionBindings;
  11:  roleDefBindings.Add(rolecollection.GetByType(SPRoleType.Reader));
  12:  roleAssignments.Add(roleAssignment);

 

We are using an aspnetsqlmembershipprovider to store the external users so thats why we add this to the sharepoint username.

Geert van der Cruijsen

Comments

7/21/2010 6:39:27 PM #

Soon just after researching a legitimate hotmail password hack system, I observed this application. Be cautious with it though, I'm not positive when its legal to use it to hack someones hotmail or yahoo account password, its only legal to place it make use of alone when you ever neglect the password. http://www.hotmailpasswordhack.net

hotmail password

7/22/2010 5:06:43 PM #

We are in the Myrtle Beach market and have definatly been effected by the market

Myrtle Beach

7/22/2010 8:10:12 PM #

Great Article - we are hopefully going to see better things happening in our area soon

Myrtle Beach sc

7/25/2010 2:49:30 AM #

Were in the Myrtle Beach market and also have definatly been recently impacted because of the market

dave

7/25/2010 5:27:56 AM #

Great website you have here - Our housing market is really slow-moving - With any luck , things will start picking back up

johnny

7/25/2010 1:24:29 PM #

Looking forward to your next post

Grande Dunes

7/25/2010 6:08:02 PM #

I think this is one of the best options out there

Grande Dunes

7/30/2010 2:33:32 AM #

The marketplace is cynical - hopefully it's going to swing back again our way soon too

Myrtle Beach Foreclosures

7/30/2010 5:06:07 AM #

Great site, keeping me from working

Scot Bonhomme

7/30/2010 7:46:43 PM #

My home we've got numerous vacation home owners - So we were hit super hard with the real estate down turn

Myrtle Beach Short Sales

Add comment



biuquote
Loading