Showing posts with label SHarePoint Document Library Multiline Text Column Filter. Show all posts
Showing posts with label SHarePoint Document Library Multiline Text Column Filter. Show all posts

Wednesday, 23 April 2014

Document Library Multiline Text Column Filter

Document Library Multiline Text Column Filter
using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
namespace FSDOCS
{
[Guid("5d5502de-7696-4a5a-8737-c98c43a6da82")]
public class WebPart1 : System.Web.UI.WebControls.WebParts.WebPart
{
TextBox txtSearch;
Label lblmsg;
Button btnFilter;
public WebPart1()
{
}
protected override void CreateChildControls()
{
base.CreateChildControls();
lblmsg = new Label();
txtSearch = new TextBox();
btnFilter = new Button();
btnFilter.Text = "Filter";
btnFilter.Click += new EventHandler(btnFilterClick);
this.Controls.Add(txtSearch);
this.Controls.Add(btnFilter);
this.Controls.Add(new LiteralControl(""));
this.Controls.Add(lblmsg);
//load all the data
string oquery = "";
try
{
SPContext.Current.Web.AllowUnsafeUpdates = true;
if (txtSearch.Text.Trim() != "")
{
oquery = "";
oquery += "" + txtSearch.Text.Trim() + "";
oquery += "";
}
//Doc Library
string strDocLibName = "Approved Documents";
//SPFolder oFolderParent = SPContext.Current.Web.Folders[strDocLibName];
//SPFolder oFolderChild = oFolderParent.SubFolders["Subfolder_Name"];
SPDocumentLibrary oDocumentLibrary = (SPDocumentLibrary)SPContext.Current.Web.Lists[strDocLibName];
SPViewCollection viewColl = oDocumentLibrary.Views;
for (int i = 0; i < viewColl.Count; i++)
{
Microsoft.SharePoint.SPView view = viewColl[i];
view.Query = oquery;
view.Update();
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
SPContext.Current.Web.AllowUnsafeUpdates = false;
txtSearch.Text = "";
}
//End Load
}
protected void btnFilterClick(object sender, EventArgs e)
{
if (txtSearch.Text.Trim() == "")
{
lblmsg.Text = "You must specify a value for this required field";
string oquery = "";
try
{
SPContext.Current.Web.AllowUnsafeUpdates = true;
if (txtSearch.Text.Trim() != "")
{
oquery = "";
oquery += "" + txtSearch.Text.Trim() + "";
oquery += "";
}
//Doc Library
string strDocLibName = "Approved Documents";
//SPFolder oFolderParent = SPContext.Current.Web.Folders[strDocLibName];
//SPFolder oFolderChild = oFolderParent.SubFolders["Subfolder_Name"];
SPDocumentLibrary oDocumentLibrary = (SPDocumentLibrary)SPContext.Current.Web.Lists[strDocLibName];
SPViewCollection viewColl = oDocumentLibrary.Views;
for (int i = 0; i < viewColl.Count; i++)
{
Microsoft.SharePoint.SPView view = viewColl[i];
view.Query = oquery;
view.Update();
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
SPContext.Current.Web.AllowUnsafeUpdates = false;
txtSearch.Text = "";
}
}
else
{
string oquery = "";
try
{
SPContext.Current.Web.AllowUnsafeUpdates = true;
if (txtSearch.Text.Trim() != "")
{
oquery = "";
oquery += "" + txtSearch.Text.Trim() + "";
oquery += "";
}
//Doc Library
string strDocLibName = "Approved Documents";
//SPFolder oFolderParent = SPContext.Current.Web.Folders[strDocLibName];
//SPFolder oFolderChild = oFolderParent.SubFolders["Subfolder_Name"];
SPDocumentLibrary oDocumentLibrary = (SPDocumentLibrary)SPContext.Current.Web.Lists[strDocLibName];
SPViewCollection viewColl = oDocumentLibrary.Views;
for (int i = 0; i < viewColl.Count; i++)
{
Microsoft.SharePoint.SPView view = viewColl[i];
view.Query = oquery;
view.Update();
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
SPContext.Current.Web.AllowUnsafeUpdates = false;
txtSearch.Text = "";
}
}
}
}
}