SharePoint 2013 中使用客户化的 (Custom) Filter web part 过滤OOB list view

本文讲述如何在SharePoint 2013 中使用客户化的 (Custom) Filter web part 过滤OOB list view。

比如有这样一个需求,用户内网门户上有个文档库列表视图web part,现在要求当用户登录时只能看到属于本部门的文档,不使用权限设置,不打破权限继承。

1.  给文档库添加一个Department字段(Choice或Metadata,可多选)

2. 新建一个 Farm solution

3. 新建一个FilterByDepartment web part

4.  FilterByDepartment.cs 代码

using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using System.Collections.ObjectModel;

namespace Filters.FilterByDepartment
{
    [ToolboxItemAttribute(false)]
    public class FilterByFilterByDepartment : System.Web.UI.WebControls.WebParts.WebPart, ITransformableFilterValues
    {
        string propertyValue = null;
        protected override void CreateChildControls()
        {         

        }

        public bool AllowAllValue
        {
            get { return true; }
        }

        public bool AllowEmptyValue
        {
            get { return true; }
        }

        public bool AllowMultipleValues
        {
            get { return false; }
        }

        public string ParameterName
        {
            get { return "Department"; }
        }

        public System.Collections.ObjectModel.ReadOnlyCollection<string> ParameterValues
        {
            get
            {
                var currentUser = SPContext.Current.Web.CurrentUser;
                var userId = currentUser.ID;               
                var userList = SPContext.Current.Web.SiteUserInfoList;
                var userItem = userList.GetItemById(userId);
                propertyValue = userItem["Department"] == null ? null : userItem["Department"].ToString();
                string[] values = new string[] { propertyValue };
                return new ReadOnlyCollection<string>(values);
            }
        }

        [ConnectionProvider("Connection Property Filter", "ITransformableFilterValues", AllowsMultipleConnections = true)]
        public ITransformableFilterValues SetConnectionInterface()
        {
            return this;
        }
    }
}


5. 部署解决方案

6. 在页面上添加文档库视图和FilterByDepartment web part,并连接

 

7. 隐藏FilterByDepartment web part

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值