程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> 關於C# >> moss 列表 權限 實現代碼

moss 列表 權限 實現代碼

編輯:關於C#
 

* User: Administrator Date: 10-07-16 Time: 10:58
* Created in $/SYDXWF/SYDXWF/EventHandlerSYDXWF
* 個人日歷權限設置
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Workflow;

namespace EventHandlerSYDXWF
{
public class PersonalCalendarAuthorizationEventHandler : SPItemEventReceiver
{

/// <summary>
/// 添加事件
/// </summary>
/// <param name="properties"></param>
public override void ItemAdded(SPItemEventProperties properties)
{
try
{
this.DisableEventFiring();
SPListItem item = properties.ListItem;
item["Title"] = item.ID.ToString();
item.Update();

this.SetAuthorization(properties);
}
catch (Exception ex)
{

}
}
/// <summary>
/// 權限設置函數
/// </summary>
/// <param name="properties">當前列表屬性集合</param>
/// <param name="refUser">用戶</param>
public void SetAuthorization(SPItemEventProperties properties)
{
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(properties.SiteId))
{
using (SPWeb web = site.OpenWeb(properties.OpenWeb().ID))
{
SPList list = web.Lists[properties.ListId];
SPListItem item = list.Items.GetItemById(properties.ListItemId);
item.BreakRoleInheritance(false);

//查看對象
SPUser refUser = null;
SPRoleAssignment roleAss = null;
SPRoleDefinition roleDefine = null;

refUser = web.AllUsers.GetByID(properties.CurrentUserId);
roleAss = new SPRoleAssignment(refUser);
roleDefine = web.RoleDefinitions.GetByType(SPRoleType.Contributor);
roleAss.RoleDefinitionBindings.Add(roleDefine);
item.RoleAssignments.Add(roleAss);

if (item["ViewObject"] != null)
{
SPFieldUserValueCollection userValues = item["ViewObject"] as SPFieldUserValueCollection;
foreach (SPFieldUserValue userValue in userValues)
{

if (userValue.User == null)
{
SPGroup group = web.SiteGroups.GetByID(userValue.LookupId);
roleAss = new SPRoleAssignment(group);
}
else
{
roleAss = new SPRoleAssignment(userValue.User);
}
roleDefine = web.RoleDefinitions.GetByType(SPRoleType.Reader);
roleAss.RoleDefinitionBindings.Add(roleDefine);
item.RoleAssignments.Add(roleAss);
}
}

item.Update();

}
}
});
}
catch (Exception ex)
{

}
}

}
}

 

 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved