过滤列表文档
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>
103
<asp:LinkButton ID="All" runat="server" CommandName="ALL" OnClick="LinkButton_Click" >All</asp:LinkButton>
104
<asp:LinkButton ID="A" runat="server" CommandName="A" OnClick="LinkButton_Click">A</asp:LinkButton>
105
<asp:LinkButton ID="B" runat="server" CommandName="B" OnClick="LinkButton_Click">B</asp:LinkButton>
106
<asp:LinkButton ID="C" runat="server" CommandName="C" OnClick="LinkButton_Click">C</asp:LinkButton>
107
<asp:LinkButton ID="D" runat="server" CommandName="D" OnClick="LinkButton_Click">D</asp:LinkButton>
108
<asp:LinkButton ID="E" runat="server" CommandName="E" OnClick="LinkButton_Click">E</asp:LinkButton>
109
<asp:LinkButton ID="F" runat="server" CommandName="F" OnClick="LinkButton_Click">F</asp:LinkButton>
110
<asp:LinkButton ID="G" runat="server" CommandName="G" OnClick="LinkButton_Click">G</asp:LinkButton>
111
<asp:LinkButton ID="H" runat="server" CommandName="H" OnClick="LinkButton_Click">H</asp:LinkButton>
112
<asp:LinkButton ID="I" runat="server" CommandName="I" OnClick="LinkButton_Click">I</asp:LinkButton>
113
<asp:LinkButton ID="J" runat="server" CommandName="J" OnClick="LinkButton_Click">J</asp:LinkButton>
114
<asp:LinkButton ID="K" runat="server" CommandName="K" OnClick="LinkButton_Click">K</asp:LinkButton>
115
<asp:LinkButton ID="L" runat="server" CommandName="L" OnClick="LinkButton_Click">L</asp:LinkButton>
116
<asp:LinkButton ID="M" runat="server" CommandName="M" OnClick="LinkButton_Click">M</asp:LinkButton>
117
<asp:LinkButton ID="N" runat="server" CommandName="N" OnClick="LinkButton_Click">N</asp:LinkButton>
118
<asp:LinkButton ID="O" runat="server" CommandName="O" OnClick="LinkButton_Click">O</asp:LinkButton>
119
<asp:LinkButton ID="P" runat="server" CommandName="P" OnClick="LinkButton_Click">P</asp:LinkButton>
120
<asp:LinkButton ID="Q" runat="server" CommandName="Q" OnClick="LinkButton_Click">Q</asp:LinkButton>
121
<asp:LinkButton ID="R" runat="server" CommandName="R" OnClick="LinkButton_Click">R</asp:LinkButton>
122
<asp:LinkButton ID="S" runat="server" CommandName="S" OnClick="LinkButton_Click">S</asp:LinkButton>
123
<asp:LinkButton ID="T" runat="server" CommandName="T" OnClick="LinkButton_Click">T</asp:LinkButton>
124
<asp:LinkButton ID="U" runat="server" CommandName="U" OnClick="LinkButton_Click">U</asp:LinkButton>
125
<asp:LinkButton ID="V" runat="server" CommandName="V" OnClick="LinkButton_Click">V</asp:LinkButton>
126
<asp:LinkButton ID="W" runat="server" CommandName="W" OnClick="LinkButton_Click">W</asp:LinkButton>
127
<asp:LinkButton ID="X" runat="server" CommandName="X" OnClick="LinkButton_Click">X</asp:LinkButton>
128
<asp:LinkButton ID="Y" runat="server" CommandName="Y" OnClick="LinkButton_Click">Y</asp:LinkButton>
129
<asp:LinkButton ID="Z" runat="server" CommandName="Z" OnClick="LinkButton_Click">Z</asp:LinkButton>
130
</td>
131
</tr>
132
</table>
<%@ 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
try14
{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
else37
{38
All.ForeColor = System.Drawing.Color.Red;39
}40
}41
else42
{43
((LinkButton)this.FindControl(Request["FitlerString"])).ForeColor = System.Drawing.Color.Red;44
}45
});46
}47
catch48
{49
50
}51
finally52
{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
try65
{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
else80
{81
oView.Query = "";82
}83
oView.Update();84
myWeb.AllowUnsafeUpdates = false; 85
});86
}87
catch88
{89
}90
finally91
{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> 103
<asp:LinkButton ID="All" runat="server" CommandName="ALL" OnClick="LinkButton_Click" >All</asp:LinkButton> 104
<asp:LinkButton ID="A" runat="server" CommandName="A" OnClick="LinkButton_Click">A</asp:LinkButton> 105
<asp:LinkButton ID="B" runat="server" CommandName="B" OnClick="LinkButton_Click">B</asp:LinkButton> 106
<asp:LinkButton ID="C" runat="server" CommandName="C" OnClick="LinkButton_Click">C</asp:LinkButton> 107
<asp:LinkButton ID="D" runat="server" CommandName="D" OnClick="LinkButton_Click">D</asp:LinkButton> 108
<asp:LinkButton ID="E" runat="server" CommandName="E" OnClick="LinkButton_Click">E</asp:LinkButton> 109
<asp:LinkButton ID="F" runat="server" CommandName="F" OnClick="LinkButton_Click">F</asp:LinkButton> 110
<asp:LinkButton ID="G" runat="server" CommandName="G" OnClick="LinkButton_Click">G</asp:LinkButton> 111
<asp:LinkButton ID="H" runat="server" CommandName="H" OnClick="LinkButton_Click">H</asp:LinkButton> 112
<asp:LinkButton ID="I" runat="server" CommandName="I" OnClick="LinkButton_Click">I</asp:LinkButton> 113
<asp:LinkButton ID="J" runat="server" CommandName="J" OnClick="LinkButton_Click">J</asp:LinkButton> 114
<asp:LinkButton ID="K" runat="server" CommandName="K" OnClick="LinkButton_Click">K</asp:LinkButton> 115
<asp:LinkButton ID="L" runat="server" CommandName="L" OnClick="LinkButton_Click">L</asp:LinkButton> 116
<asp:LinkButton ID="M" runat="server" CommandName="M" OnClick="LinkButton_Click">M</asp:LinkButton> 117
<asp:LinkButton ID="N" runat="server" CommandName="N" OnClick="LinkButton_Click">N</asp:LinkButton> 118
<asp:LinkButton ID="O" runat="server" CommandName="O" OnClick="LinkButton_Click">O</asp:LinkButton> 119
<asp:LinkButton ID="P" runat="server" CommandName="P" OnClick="LinkButton_Click">P</asp:LinkButton> 120
<asp:LinkButton ID="Q" runat="server" CommandName="Q" OnClick="LinkButton_Click">Q</asp:LinkButton> 121
<asp:LinkButton ID="R" runat="server" CommandName="R" OnClick="LinkButton_Click">R</asp:LinkButton> 122
<asp:LinkButton ID="S" runat="server" CommandName="S" OnClick="LinkButton_Click">S</asp:LinkButton> 123
<asp:LinkButton ID="T" runat="server" CommandName="T" OnClick="LinkButton_Click">T</asp:LinkButton> 124
<asp:LinkButton ID="U" runat="server" CommandName="U" OnClick="LinkButton_Click">U</asp:LinkButton> 125
<asp:LinkButton ID="V" runat="server" CommandName="V" OnClick="LinkButton_Click">V</asp:LinkButton> 126
<asp:LinkButton ID="W" runat="server" CommandName="W" OnClick="LinkButton_Click">W</asp:LinkButton> 127
<asp:LinkButton ID="X" runat="server" CommandName="X" OnClick="LinkButton_Click">X</asp:LinkButton> 128
<asp:LinkButton ID="Y" runat="server" CommandName="Y" OnClick="LinkButton_Click">Y</asp:LinkButton> 129
<asp:LinkButton ID="Z" runat="server" CommandName="Z" OnClick="LinkButton_Click">Z</asp:LinkButton> 130
</td>131
</tr>132
</table>
如果你不知道如何使用quickpart,请进入这里

浙公网安备 33010602011771号