Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Setting Permission For a list in C#

  Asked By: Sampat    Date: Dec 04    Category: Sharepoint    Views: 4238

I want to set permission for a list/document Library in sharePoint through Code in C#.My code looks like this.

SPFolder mylibrary = objWeb.Folders["Proposal"];
myListItem.HasUniqueRoleAssignments.ToString());
myListItem.BreakRoleInheritance(false);
SPRoleDefinitionCollection webroledefinitions = objWeb.RoleDefinitions;
SPGroup group = objWeb.SiteGroups[“MyGroup”];
SPRoleAssignment roleassignment = new SPRoleAssignment(group);
roleassignment.RoleDefinitionBindings.Add(webroledefinitions[“Design”]);
myListItem.RoleAssignments.Add(roleassignment);

It builts sucessfully but gives an error When the custom action executes saying

"The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again."

Due to which the custom action is performed but not the permission which i want.
It retrives the permission from the parent site .

Moreover i am using Quest List Form..
If anyone has encountered this error befor, Please help me out here.

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Bahadur Kotoky     Answered On: Dec 04

i have done permissions for list  items.but i am getting u r question.u have deleted inherited permissions of that perticular item.after that wht u want to do.u want to add one group  to that item?

 
Answer #2    Answered By: Jeremey Avery     Answered On: Dec 04

I too came across this issue in different scenarios so to overcome this issue in my case i did a post back  to the page  so that it executes the same set  of code  next time and then it worked fine. I am not sure in which context ur executing that lines of code. Myne is a webcontrol thats placed in master page.

 
Answer #3    Answered By: Mariel Ferrell     Answered On: Dec 04

Thanks for the suggestions and comments on the above post..Well I sorted out the error  after some tedious work.Actually it was a permission  issue..I dont had permsion to assign the permission for a specific document library  or List...

 
Didn't find what you were looking for? Find more on Setting Permission For a list in C# Or get search suggestion and latest updates.




Tagged: