现在的位置: 首页 > 综合 > 正文

过滤列表文档

2012年01月18日 ⁄ 综合 ⁄ 共 5572字 ⁄ 字号 评论关闭

Requirement:

   最近客户在列表文档库中上传了多很文档,如果他们需要看一个文档,要翻很多页才能找到,他们希望用A.B.C...Z 字母开头的进行过滤。当点A的时候,显示A开头的所有文档。

 

 

 

Solution:

   我想要实现这种功能有很多种方法,下面我给大家介绍我如何实现的这个功能。

 

    step1,我创建了一个叫Brand的View,这个 view专门来过滤文档的。

 

    step2,添加一个quickpart 容器webpart,用他来包装我们开发的过滤用户控件。

 

    User Control代码 如下:

 

    

  1<%@ Control Language="C#" Debug="true" %>
  2<%@ Import Namespace="Microsoft.SharePoint" %>
  3<%@ Import Namespace="System.Data"  %>
  4
  5<script runat="server">
  6    string redirectUrl="/BizDevMarketing/ImageVideoLibrary/Forms/AegisCompany.aspx?RootFolder=%2FBizDevMarketing%2FImageVideoLibrary%2FAegis%20Company%20Logos";
  7    protected void Page_Load(object sender, EventArgs e)
  8    {
  9        if (!IsPostBack)
 10        {
 11            SPSite mySite = null;
 12            SPWeb myWeb = null;
 13            try
 14            {
 15                SPSecurity.RunWithElevatedPrivileges(delegate()
 16                {
 17                    mySite = new SPSite(SPContext.Current.Site.ID);
 18                    myWeb = mySite.OpenWeb(SPContext.Current.Web.ID);
 19    
 20                    SPList oList = myWeb.Lists["Image & Video Library"];
 21                    SPView oView = oList.Views["AegisCompany"];
 22    
 23                    if (string.IsNullOrEmpty(this.Request["FitlerString"]))
 24                    {
 25                        if (!string.IsNullOrEmpty(oView.Query))
 26                        {
 27                            myWeb.AllowUnsafeUpdates = true;
 28                            oView.Query = "";
 29                            oView.Update();
 30                            myWeb.AllowUnsafeUpdates = false;
 31    
 32                            mySite = null;
 33                            myWeb = null;
 34                            this.Response.Redirect(redirectUrl, true);
 35                        }

 36                        else
 37                        {
 38                            All.ForeColor = System.Drawing.Color.Red;
 39                        }

 40                    }

 41                    else
 42                    {
 43                        ((LinkButton)this.FindControl(Request["FitlerString"])).ForeColor = System.Drawing.Color.Red;
 44                    }

 45                }
);
 46            }

 47            catch
 48            {
 49    
 50            }

 51            finally
 52            {
 53                mySite = null;
 54                myWeb = null;
 55    
 56            }
    
 57        }

 58    }

 59    protected void LinkButton_Click(object sender, EventArgs e)
 60    {
 61        LinkButton tempButton = (LinkButton)sender;
 62        SPSite mySite = null;
 63        SPWeb myWeb = null;
 64        try
 65        {
 66            SPSecurity.RunWithElevatedPrivileges(delegate()
 67            {
 68                mySite = new SPSite(SPContext.Current.Site.ID);
 69                myWeb = mySite.OpenWeb(SPContext.Current.Web.ID);
 70                myWeb.AllowUnsafeUpdates = true;
 71
 72                SPList oList = myWeb.Lists["Image & Video Library"];
 73                SPView oView = oList.Views["AegisCompany"];
 74                if (tempButton.CommandName != "ALL")
 75                {
 76                    oView.Query = "<Where><BeginsWith><FieldRef Name=\"FileLeafRef\" />" +
 77                    "<Value Type=\"Text\">" + tempButton.CommandName + "</Value></BeginsWith></Where>";
 78                }

 79                else
 80                {
 81                    oView.Query = "";
 82                }

 83                oView.Update();
 84                myWeb.AllowUnsafeUpdates = false;                
 85            }
);
 86        }

 87        catch
 88        {
 89        }

 90        finally
 91        {
 92            mySite = null;
 93            myWeb = null;
 94            this.Response.Redirect(redirectUrl + "&FitlerString=" + tempButton.CommandName, true);    
 95        }
        
 96    }

 97
 98   
 99</script>
100<table class="ms-quicklaunchheader" style="width:500px " >
101<tr>
102<td>&nbsp;&nbsp;&nbsp;
103<asp:LinkButton ID="All" runat="server" CommandName="ALL" OnClick="LinkButton_Click" >All</asp:LinkButton>&nbsp;
104<asp:LinkButton ID="A" runat="server"  CommandName="A" OnClick="LinkButton_Click">A</asp:LinkButton>&nbsp;
105<asp:LinkButton ID="B" runat="server" CommandName="B" OnClick="LinkButton_Click">B</asp:LinkButton>&nbsp;
106<asp:LinkButton ID="C" runat="server" CommandName="C" OnClick="LinkButton_Click">C</asp:LinkButton>&nbsp;
107<asp:LinkButton ID="D" runat="server" CommandName="D" OnClick="LinkButton_Click">D</asp:LinkButton>&nbsp;
108<asp:LinkButton ID="E" runat="server" CommandName="E" OnClick="LinkButton_Click">E</asp:LinkButton>&nbsp;
109<asp:LinkButton ID="F" runat="server" CommandName="F" OnClick="LinkButton_Click">F</asp:LinkButton>&nbsp;
110<asp:LinkButton ID="G" runat="server" CommandName="G" OnClick="LinkButton_Click">G</asp:LinkButton>&nbsp;
111<asp:LinkButton ID="H" runat="server" CommandName="H" OnClick="LinkButton_Click">H</asp:LinkButton>&nbsp;
112<asp:LinkButton ID="I" runat="server" CommandName="I" OnClick="LinkButton_Click">I</asp:LinkButton>&nbsp;
113<asp:LinkButton ID="J" runat="server" CommandName="J" OnClick="LinkButton_Click">J</asp:LinkButton>&nbsp;
114<asp:LinkButton ID="K" runat="server" CommandName="K" OnClick="LinkButton_Click">K</asp:LinkButton>&nbsp;
115<asp:LinkButton ID="L" runat="server" CommandName="L" OnClick="LinkButton_Click">L</asp:LinkButton>&nbsp;
116<asp:LinkButton ID="M" runat="server" CommandName="M" OnClick="LinkButton_Click">M</asp:LinkButton>&nbsp;
117<asp:LinkButton ID="N" runat="server" CommandName="N" OnClick="LinkButton_Click">N</asp:LinkButton>&nbsp;
118

抱歉!评论已关闭.