【问题标题】:Sharepoint 2013 - Permission to only allow for the document creator to EDIT the documentSharepoint 2013 - 仅允许文档创建者编辑文档的权限
【发布时间】:2018-06-28 09:18:07
【问题描述】:

是否有一种方法可以控制 SharePoint 的权限,以便将文档上传到文档库的用户是唯一可以编辑或删除该文件的用户?我希望其他用户能够打开该文件,但以只读方式打开且未检出(我不在乎他们是否将其保存到计算机并更改本地副本)。

我想这应该是一个允许所有人添加和删除文件的权限组,但只有添加的文件的创建者才能签出和编辑。

感谢您的帮助!

【问题讨论】:

    标签: sharepoint-2013


    【解决方案1】:

    您可以为这个库创建事件接收器,当文件上传时,打破权限继承并为作者和其他人(可能是一个组)分配唯一权限。

    这是来自technet的示例代码。

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Utilities;
    using System.Collections.Specialized;
    
    namespace SurveyPermissionsMgr
    {
        class ThreeMonthSurveyPermissionsMgr : SPItemEventReceiver
        {
            public override void ItemAdded(SPItemEventProperties properties)
            {
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        using (SPSite site = new SPSite(properties.WebUrl))
                        {
                            site.AllowUnsafeUpdates = true;
    
                            using (SPWeb web = site.OpenWeb())
                            {
                                web.AllowUnsafeUpdates = true;
    
                                SPListItem myItem = web.Lists[properties.ListId].GetItemById(properties.ListItem.ID); //  GET LIST OBJECT FROM SPWEB, NOT EVENT PROPERTIES
    
                                myItem.BreakRoleInheritance(false);
    
                                this.DisableEventFiring();
                                myItem.Update();
    
                                SPMember member = web.SiteGroups["My Group"];
                                SPPrincipal principal = (SPPrincipal)member;
                                SPRoleDefinition roledefinition = web.RoleDefinitions.GetByType(SPRoleType.Contributor);
                                SPRoleAssignment myRoleAssignment = new SPRoleAssignment(principal);
                                myRoleAssignment.RoleDefinitionBindings.Add(roledefinition);
                                myItem.RoleAssignments.Add(myRoleAssignment);
    
                                string managerstring = myItem["Manager Account Id"].ToString();
                                SPUser manager = web.EnsureUser(managerstring);
    
                                myItem["Manager"] = manager;
    
                                SPPrincipal managerprincipal = (SPPrincipal)manager;
                                SPRoleDefinition managerroledefinition = web.RoleDefinitions.GetByType(SPRoleType.Reader);
                                SPRoleAssignment ManagerRoleAssignment = new SPRoleAssignment(managerprincipal);
                                ManagerRoleAssignment.RoleDefinitionBindings.Add(managerroledefinition);
                                myItem.RoleAssignments.Add(ManagerRoleAssignment);
    
                                string associatestring = myItem["Author"].ToString();
                                int userid = Convert.ToInt32(associatestring.Substring(0, associatestring.IndexOf(";#")));
                                SPUser associate = web.AllUsers.GetByID(userid);
                                SPPrincipal associateprincipal = (SPPrincipal)associate;
                                SPRoleDefinition associateroledefinition = web.RoleDefinitions.GetByType(SPRoleType.Reader);
                                SPRoleAssignment AssociateRoleAssignment = new SPRoleAssignment(associateprincipal);
                                AssociateRoleAssignment.RoleDefinitionBindings.Add(associateroledefinition);
                                myItem.RoleAssignments.Add(AssociateRoleAssignment);
    
                                myItem.Update();
                                this.EnableEventFiring();
                                web.AllowUnsafeUpdates = false;
                                site.AllowUnsafeUpdates = false;
    
                                //Handle messaging
                                StringDictionary dict = new StringDictionary();
                                dict.Add("to", manager.Email);
                                dict.Add("from", "us@you.com");
                                dict.Add("subject", "bla bla bla");
                                string msgbody = "bla bla bla";
                                SPUtility.SendEmail(web, dict, msgbody);
                            }
                        }
                    });
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-02-24
      • 1970-01-01
      • 2014-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多