<CharlieDigital/> Programming, Politics, and uhh…pineapples


Adding Users To A Document Workspace

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.

        // Add the assignment to the web.

        // Update the web.

Note that when you create a new sub-web, by default, there are 5 role definitions defined for you already. These are:

  1. Full Control
  2. Design
  3. Contribute
  4. Read
  5. Limited Access

Posted by Charles Chen

Filed under: Dev, SharePoint Comments Off
Comments (0) Trackbacks (0)

Sorry, the comment form is closed at this time.

Trackbacks are disabled.