Creating WebApp Permission Level




Go back to index

How to create web application permission level


Following code block explains how to programmatically create a permission level for a web application.

      using System;
      using SPTool.Library;
      using System.Collections;
      
      namespace SPTool.Test
      {
          class Program
          {
              static void Main(string[] args)
              {
                  SPTWebApplication webApplication = new SPTWebApplication("http://sptool");

                  // Permissions to be granted ( AddDelPrivateWebParts, UpdatePersonalWebParts - Permissions removed)
                  ArrayList grantPermissions = new ArrayList();
                  grantPermissions.AddRange(new string[] { "ViewListItems", "AddListItems", "EditListItems", "DeleteListItems",
                      "ApproveItems", "OpenItems", "ViewVersions", "DeleteVersions", "CancelCheckout", "ManagePersonalViews",
                      "ManageLists", "ViewFormPages", "Open", "ViewPages", "AddAndCustomizePages", "ApplyThemeAndBorder",
                      "ApplyStyleSheets", "ViewUsageData", "CreateSSCSite", "ManageSubwebs","CreateGroups","ManagePermissions",
                      "BrowseDirectories", "BrowseUserInfo", "ManageWeb", "UseClientIntegration", "UseRemoteApis", "ManageAlerts",
                      "CreateAlerts", "EditMyUserInfo", "EnumeratePermissions" });

                  // Permissions to be denied
                  ArrayList denyPermissions = new ArrayList();
                  denyPermissions.AddRange(new string[] { "AddDelPrivateWebParts", "UpdatePersonalWebParts" });

                  // Create Permission Level in the web application
                  SPTReturn returnObj = webApplication.CreatePermissionLevel("SPTool Permissions", "SPTool Permissions", grantPermissions, denyPermissions);

                  // Check the status of creating permission level
                  if (returnObj.State == SPTState.Success)
                  {
                      // Creating Permission Level Successful, lets create another dummy permission level
                      returnObj = webApplication.CreatePermissionLevel("Dummy Permissions", "Dummy Permissions", grantPermissions, denyPermissions);
                  }
                  else
                  {
                      // Creating Permission Level Failed
                  }
              }
          }
      }


Go back to index