| Author |
Message |
barre
Guest
|
Posted:
Mon Oct 24, 2005 12:51 pm Post subject:
Creating Securtiy Groups Programmaticaly |
|
|
Hi all,
I was given the assignment to implement a little program that is able
to read data from an XML file and then create area's and groups on the
portal site.
I'm having a problem with creating the groups. Wheneven I create a
group, the group is created. No problems so far, but when I want to
check it's permissions on the portal site, I get the following error.
"Object not set to an instance of an object".
Here is the code with wich I am creating the Groups :
SPSite site = new SPSite("http://MyURL");
SPWeb PortalWeb = site.OpenWeb();
SPRights Rights = new SPRights();
PortalWeb.AllowUnsafeUpdates = true;
PortalWeb.Roles.Add("NewGroup", "This is my new
group",PortalWeb.Roles["Administrator"].PermissionMask);
PortalWeb.Roles["NewGroup"].Update();
I realy hope someone can help me with this.
Greetz
Barre |
|
| Back to top |
|
 |
Gustavo
Guest
|
Posted:
Mon Oct 24, 2005 12:51 pm Post subject:
RE: Creating Securtiy Groups Programmaticaly |
|
|
Hi Greetz,
And if you try with
PortalWeb.Roles.Add("NewGroup", "This is my new
group", SPRights.FullMask);
instead of
PortalWeb.Roles.Add("NewGroup", "This is my new
group",PortalWeb.Roles["Administrator"].PermissionMask);
?
Saludes,
Gustavo
http://www.gavd.net/servers/default.aspx
"barre" wrote:
| Quote: | Hi all,
I was given the assignment to implement a little program that is able
to read data from an XML file and then create area's and groups on the
portal site.
I'm having a problem with creating the groups. Wheneven I create a
group, the group is created. No problems so far, but when I want to
check it's permissions on the portal site, I get the following error.
"Object not set to an instance of an object".
Here is the code with wich I am creating the Groups :
SPSite site = new SPSite("http://MyURL");
SPWeb PortalWeb = site.OpenWeb();
SPRights Rights = new SPRights();
PortalWeb.AllowUnsafeUpdates = true;
PortalWeb.Roles.Add("NewGroup", "This is my new
group",PortalWeb.Roles["Administrator"].PermissionMask);
PortalWeb.Roles["NewGroup"].Update();
I realy hope someone can help me with this.
Greetz
Barre
|
|
|
| Back to top |
|
 |
Gustavo
Guest
|
Posted:
Mon Oct 24, 2005 4:51 pm Post subject:
Re: Creating Securtiy Groups Programmaticaly |
|
|
Hi again,
Yes, I did it a couple of times. Something like:
SPWeb MySite = MySrv.Sites[currentUserProfile.PersonalUrl].OpenWeb();
//MySrv is the Virtual Server used for this site
//currentUserProfile is the current user, gived by his LoginName
//But you can a reference for MySite in different ways
//Make a new site
SPWeb MyPFSite = null;
MyPFSite = MySite.Webs.Add("Name", "Desc", "", 1033, "Template", true, false);
//Make a new role for the site
MyPFSite.Roles.Add("Owner", "Desc Owner", SPRights.ViewListItems |
SPRights.ViewPages | SPRights.BrowseUserInfo |
SPRights.AddListItems);
//Add an user to the rol
MyPFSite.Roles["Owner"].AddUser(CurUser.LoginName, CurUser.Email,
CurUser.Name, CurUser.Notes);
//CurUser is the current user, but it can be any user
And it works...
Saludes,
Gustavo
http://www.gavd.net/servers/default.aspx
"barre" wrote:
| Quote: | Hi Gustavo,
thx for the reply !
I'v trie youre suggestion, but no luck. Have you done this before? If
so how did you do it?
greetz, Barre
|
|
|
| Back to top |
|
 |
barre
Guest
|
Posted:
Mon Oct 24, 2005 4:51 pm Post subject:
Re: Creating Securtiy Groups Programmaticaly |
|
|
Hi Gustavo,
thx for the reply !
I'v trie youre suggestion, but no luck. Have you done this before? If
so how did you do it?
greetz, Barre |
|
| Back to top |
|
 |
barre
Guest
|
Posted:
Mon Oct 24, 2005 4:51 pm Post subject:
Re: Creating Securtiy Groups Programmaticaly |
|
|
Hey Gustavo,
I've tried you're suggestion, but no luck. Have you ever done what i'm
trying to do? If so, how did you do it?
Barre
Gustavo schreef:
| Quote: | Hi Greetz,
And if you try with
PortalWeb.Roles.Add("NewGroup", "This is my new
group", SPRights.FullMask);
instead of
PortalWeb.Roles.Add("NewGroup", "This is my new
group",PortalWeb.Roles["Administrator"].PermissionMask);
?
Saludes,
Gustavo
http://www.gavd.net/servers/default.aspx
"barre" wrote:
Hi all,
I was given the assignment to implement a little program that is able
to read data from an XML file and then create area's and groups on the
portal site.
I'm having a problem with creating the groups. Wheneven I create a
group, the group is created. No problems so far, but when I want to
check it's permissions on the portal site, I get the following error.
"Object not set to an instance of an object".
Here is the code with wich I am creating the Groups :
SPSite site = new SPSite("http://MyURL");
SPWeb PortalWeb = site.OpenWeb();
SPRights Rights = new SPRights();
PortalWeb.AllowUnsafeUpdates = true;
PortalWeb.Roles.Add("NewGroup", "This is my new
group",PortalWeb.Roles["Administrator"].PermissionMask);
PortalWeb.Roles["NewGroup"].Update();
I realy hope someone can help me with this.
Greetz
Barre
|
|
|
| Back to top |
|
 |
Barre
Guest
|
Posted:
Tue Oct 25, 2005 4:51 pm Post subject:
Re: Creating Securtiy Groups Programmaticaly |
|
|
Has anyone done this on portal level. I want to create a group on
portal level. not on area level. Or isn't there a difference? |
|
| Back to top |
|
 |
|
|
|
|