有sharepint用代码实现权限管控的问题,有哪位大侠帮忙看看下面的代码在VS中如何操作:
一旦提交申请,就只有本人、审批人、管理员可以看到。而且审批人有“批准”权限。
为实现这个功能,需要处理列表的 Create 事件。
先断开现有的继承权限。
item.BreakRoleInheritance(false);
然后,绑定新的权限。
protected void bind_role(SPListItem item, SPPrincipal principal, SPRoleDefinition definition)
{
try
{
SPRoleAssignment assignment = new SPRoleAssignment(principal);
assignment.RoleDefinitionBindings.Add(definition);
item.RoleAssignments.Add(assignment);
}
catch (Exception ex)
{
throw ex;
}
}
对某个用户执行绑定角色的操作。
bind_role(item, user, web.RoleDefinitions["参与讨论"]);
Eventhandler
ItemAdded
1.Start Microsoft Visual Studio 2010.
2.On the File menu, point to New, and then click Project.
3.In Project Types, under Visual Basic or C#, select Event Receiver.
4.Type DeletingEventReceiver as the project name. Click OK.
5.In the SharePoint Customization Wizard, choose Deploy as a sandboxed solution. Click Next.
6.In the Choose Event Receiver Settings dialog, select List Item Events in the What type of event receiver do you want? dropdown.
7.In the What item should be the event source? dropdown, choose Tasks.
8.Choose the An item is being deleted option in the Handle the following events list. Click Finish.
9.In the EventReceiver1 file that is created, insert the following code in the ItemDeleting method.
properties.Status = SPEventReceiverStatus.CancelWithError;
properties.ErrorMessage = "Deleting items from " + properties.RelativeWebUrl + " is not supported.";
10.Press F5 to deploy the solution.
11.Navigate to a task list and select an item in the list. Click the Delete Item button on the Server ribbon.
12.Observe the error message.