In WSS3, the process of adding users to a document workspace (or any sub-web) has changed from WSS2. The following snippet will allow you to add a user (I've only tested with users mapped to domain accounts) to the workspace:
using(SPSite site = new SPSite("http://ashelia:2345")) { using(SPWeb workspace = site.OpenWeb()) { string resourceLogin = "ASHELIA\\cchen"; // Ensure that the user exists and conveniently, get // an SPUser reference. SPUser user = workspace.EnsureUser(resourceLogin); // Create a new SPRoleAssignment for the user. SPRoleAssignment assignment = new SPRoleAssignment( user.LoginName, user.LoginName, user.Name, user.Notes ); // Add the "Contribute" role definition to the role // assignment. assignment.RoleDefinitionBindings.Add( workspace.RoleDefinitions["Contribute"] ); // Add the assignment to the web. workspace.RoleAssignments.Add(assignment); // Update the web. workspace.Update(); } }
Note that when you create a new sub-web, by default, there are 5 role definitions defined for you already. These are:
Remember Me
newtelligence dasBlog 1.8.5223.0
This site is a combo blog/portfolio for me, Charles Chen.
Sign In