How to manage column based access control in Sharepoint lists?

后端 未结 2 1325
北恋
北恋 2020-12-06 08:12

I\'m making issue tracking portal based on Sharepoint. Users should be able to add entries, but in the entry itself I want one column to only be visible to a specific group

2条回答
  •  遥遥无期
    2020-12-06 08:16

    You also can do this by register a CustomAction, and change list view schema dynamic

         
    

    and in your control class:

    class ColumnPermissionAction : Control
    {
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            HideColumn();
        }
    
        private HideColumn(){
             WebPart part=//find your web part
             string colName="SecretColumn";
             if(part is ListViewWebPart){
                (part as ListViewWebPart).ListViewXml = (part as ListViewWebPart).ListViewXml.Replace(string.Format("", colName), string.Empty);
             }else if(part is XsltListViewWebPart){
                PropertyInfo property = typeof(DataFormWebPart).GetProperty("ListViewXmlDom", BindingFlags.NonPublic | BindingFlags.Instance);
                if (property != null)
                {
                    XmlNode xmlView = property.GetValue(part as XsltListViewWebPart, null) as XmlNode;
                    if (xmlView != null)
                    {
                        XmlNode node = xmlView.SelectSingleNode("//ViewFields");
                        if (node != null)
                        {
                                var field = node.SelectSingleNode(string.Format("FieldRef[@Name='{0}']", colName));
                                if (field != null)
                                {
                                    node.RemoveChild(field);
                                }
                        }
                    }
                }
             }
        }
    }
    

提交回复
热议问题