Dear All,
I want to search contents in Document Library using CAML. I have tried
few available on net but they can search contents of List.
I am using folowing code ..
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.Utilities;
public partial class SPGridExample : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SPWeb web = SPContext.Current.Web;
#region Using SPGridView to display contents of one list
SPList list = web.Lists["assignments"];
//generateGrid(spGrid, list.Items.GetDataTable().DefaultView);
#endregion
#region Using SPGridView to display contents of several lists
SPWeb rootWeb = SPContext.Current.Site.RootWeb;
SPSiteDataQuery query = new SPSiteDataQuery();
//look through all webs
query.Webs = "<Webs Scope=\"Recursive\">";
//only look through tasks lists
query.Lists = "<Lists ServerTemplate=\"107\" />";
query.ViewFields = "<FieldRef Name=\"Title\" />"
+ "<FieldRef Name=\"StartDate\" /><FieldRef Name=\"DueDate
\" />";
//get only the items where the start date is greater than
7/01/2006
query.Query = String.Format("<Where><Gt><FieldRef
Name='StartDate'/>" +
"<Value Type='DateTime' StorageTZ='TRUE'>{0}</Value></
Gt></Where>",
SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.UtcNow.AddDays(-5)));
DataTable dt = rootWeb.GetSiteData(query);
DataView dv = new DataView(dt);
generateGrid(spGridCrossWeb, dv);
#endregion
}
protected void generateGrid(SPGridView spGrid, DataView dv)
{
SPBoundField boundField = new SPBoundField();
boundField.HeaderText = "Title";
boundField.DataField = "Title";
spGrid.Columns.Add(boundField);
boundField = new SPBoundField();
boundField.HeaderText = "Start Date";
boundField.DataField = "StartDate";
spGrid.Columns.Add(boundField);
boundField = new SPBoundField();
boundField.HeaderText = "Due Date";
boundField.DataField = "DueDate";
spGrid.Columns.Add(boundField);
spGrid.DataSource = dv;
spGrid.DataBind();
}
}
Please send me solution or any other code to seach contents in
Dcoument Library
Regards,
Kamlesh ( kamlesh.k73@gmail.com)