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:
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;
We are using an aspnetsqlmembershipprovider to store the external users so thats why we add this to the sharepoint username.
Geert van der Cruijsen