if (list.BaseType == SPBaseType.DocumentLibrary && list.BaseTemplate != SPListTemplateType.ListTemplateCatalog
&& list.BaseTemplate == SPListTemplateType.DocumentLibrary && list.Description.Contains("产品"))
{
DataTable dt = ProjectBLL.GetList("ProductManager='" + DT.MOSSCommon.MUserProfile.GetCurrentUser().ToLower() + "' or PM='" + DT.MOSSCommon.MUserProfile.GetCurrentUser().ToLower() + "' ").Tables[0]; //韩强 12-29更改 增加PM可以添加发放组
for (int i = 0; i < dt.Rows.Count; i++)
{
if (dt.Rows[i]["ProjectSPID"].ToString() == list.ID.ToString())
{
ddlProduct.Items.Add(new ListItem(list.Title, list.ID.ToString()));
}
}
}
#region MOSS文档库操作
SPSecurity.RunWithElevatedPrivileges(delegate() //用此方法模拟管理员账户运行此事件处理程序
{
using (SPSite site = new SPSite(curSite.ID))
{
using (SPWeb web = site.OpenWeb(curWeb.ID))
{
Microsoft.SharePoint.Administration.SPWebApplication webApp = site.WebApplication;
webApp.FormDigestSettings.Enabled = false;
site.AllowUnsafeUpdates = true;
web.AllowUnsafeUpdates = true;
//MOSS平台创建对应的文档库
Guid curGuid = web.Lists.Add(projectName, "产品", SPListTemplateType.DocumentLibrary);
SPList curList = web.Lists[curGuid];
#region 修改文档库权限
//在产品新建的时候必须先移除掉MOSS本身的继承权限。然后添加配置管理员的完全控制权限和产品经理的只读权限。
//注意:产品经理的登录名存入数据库必须经过ToLower()的转换。发放组那块需要判断产品经理的登录名
//判断是否有权限。有的话则打破继承
if (!curList.HasUniqueRoleAssignments)
{
curList.BreakRoleInheritance(true);
}
while (curList.RoleAssignments.Count > 0)//statrt:added by shudixuan
{
site.AllowUnsafeUpdates = true;
web.AllowUnsafeUpdates = true;
curList.RoleAssignments.Remove(0);
} //end
//添加文档库字段属性,存储文档节点类型(分为中间节点和叶子节点)
curList.Fields.Add("NodeType", SPFieldType.Text, false);
curList.Fields.Add("CusVersions", SPFieldType.Text, false);
curList.Fields.Add("IsPub", SPFieldType.Text, true);
curList.Fields.Add("DTEditor", SPFieldType.Text, false);
curList.Fields.Add("SubFolderDesc", SPFieldType.Text, false);
// curList.Fields["IsPub "].h = true; //是否显示
curList.Update();
SPField Field = curList.Fields.GetField("IsPub");
Field.Hidden = true;
Field.Title = "是否显示";
Field.Update();
Field = curList.Fields.GetField("CusVersions");
Field.Title = "版本";
Field.Update();
Field = curList.Fields.GetField("NodeType");
Field.Title = "是否为目录";
Field.Update();
Field = curList.Fields.GetField("DTEditor");
Field.Title = "修改者";
Field.Update();
Field = curList.Fields.GetField("SubFolderDesc");
Field.Title = "子目录描述";
Field.Update();
//修改此文档库默认视图
SPView defaultView = curList.DefaultView;
defaultView.ViewFields.Add("NodeType");
defaultView.ViewFields.Add("CusVersions");
defaultView.ViewFields.Add("IsPub");
defaultView.ViewFields.Add("DTEditor");
defaultView.ViewFields.Add("SubFolderDesc");
defaultView.ViewFields.Delete("Editor");
defaultView.Update();
string query = "<Where><Eq><FieldRef Name='IsPub' /><Value Type='Text'>是</Value></Eq></Where>";
defaultView.Query = query;
defaultView.Update();
SPRoleAssignment ra = null;
SPRoleDefinition roleDefinition = web.RoleDefinitions.GetByType(SPRoleType.Administrator);
//给配置管理员授予完全控制权限
SPUser spUser = curWeb.SiteUsers[this.peCM.CommaSeparatedAccounts];
if (spUser != null)
{
ra = new SPRoleAssignment(spUser);
}
ra.RoleDefinitionBindings.Add(roleDefinition);
curList.RoleAssignments.Add(ra);
//给产品经理授予只读权限
roleDefinition = web.RoleDefinitions.GetByType(SPRoleType.Reader);
//spUser = web.SiteUsers[this.peProductManager.CommaSeparatedAccounts];
spUser = web.EnsureUser(this.peProductManager.CommaSeparatedAccounts);
if (spUser != null)
{
ra = new SPRoleAssignment(spUser);
}
ra.RoleDefinitionBindings.Add(roleDefinition);
curList.RoleAssignments.Add(ra);
webApp.FormDigestSettings.Enabled = true;
site.AllowUnsafeUpdates = false;
web.AllowUnsafeUpdates = false;
#endregion
}
}
});
#endregion