Set file level permissions in SharePoint using Workflow Foundation

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);
   3:  workflowProperties.Item.File.MoveTo(currentFolder + "/" + workflowProperties.Item.File.Name);
   5:  SPRoleDefinitionCollection rolecollection = web.RoleDefinitions;
   6:  SPRoleAssignmentCollection roleAssignments = workflowProperties.Item.RoleAssignments;
   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

Share on Facebook
Kick It on
Shout it
Post on Twitter

Moved to new Hosting:

Hi All,

Long time since i’ve written my last post… well here’s my excuse: Ofcourse december is filled with the holidays etc but i also went on vacation back to Thailand again in January for 3 weeks. I had a great time there but nothing techie to write about around there :)

After i came back i wanted to switch hosting providers because my old one ( didn’t support mssql and for some things I’m working on i want to do with mssql and Linq. I’ve been experimenting with the mvc framework again and i have to say i really like it. (I hope i have time to write more on that subject soon on this blog)

My new hosting provider is Digitalibiz ( and the main reason i went to them is because 1 they are cheap and 2 they have mssql support and 3 they allow multiple domains on 1 account.

When you are reading this message the dns is finally changed to my new hosting so i can get rid of the old one. Tnx people at Sohosted for the good hosting i had there for multiple years but it was time to move on. I hope Digitalibiz will be as good as they were.

Geert van der Cruijsen

Share on Facebook
Kick It on
Shout it
Post on Twitter