Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Problem creating Roles (Site Groups) in the Portal Programmatically

  Asked By: Giovanni    Date: Aug 08    Category: Sharepoint    Views: 1169

I tried using the two approaches listed below following to create Site Groups. Both work well when I try to create the site group for a WSS site but when I try to do so for the Portal it fails. It is not obvious at the first look. The site group I tried to create is listed under Manage Site Groups. I can add users to this group. But when you do “Edit Site Group Permissions” you get the error “Object reference not set to an instance of an object.”


When a user belonging to such a group tries to access the portal he gets the following error.

You cannot view this area, either because the area no longer exists, or because you do not have the rights to view this area. To change your rights, contact the site administrator.

But if I delete this site group and create it again and add the users from Sharepoint administration pages, the users are able to access the Portal.

Is there anything I need to do differently for creating a site group in a Portal Programmatically?

Using UserGroups WebService

SPSUserGroupSvc.UserGroup svc = new SPSUserGroupSvc.UserGroup();
NetworkCredential myCred = new NetworkCredential(strUsername,strPassword,strDomain);
svc.Credentials = myCred;
svc.AddRole("TestNewRole", "Testing new Role Creation", 0x00000001|0x00020000|0x00000002);


The functions AddUserToRole, RemoveUserFromRole, RemoveRole, work fine and do not give any problems.

Using SPS Object Model

SPSite spsSiteColl = new SPSite(strServerUrl);
SPWeb spsHome = spsSiteColl.OpenWeb();
if(spsHome.UserIsWebAdmin)
{
spsHome.AllowUnsafeUpdates = true;
SPRoleCollection roleColl = spsHome.Roles;
roleColl.Add(RoleName, strDesc, permissions);
spsHome.AllowUnsafeUpdates = false;
}

Share: 

 

No Answers Found. Be the First, To Post Answer.

 




Tagged: