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)

Re: Search In document Library by Daniel

Daniel
Fri Jun 29 07:15:43 CDT 2007

Have your tried the CAML Query builder?

http://www.u2u.info/Blogs/Patrick/Lists/Posts/Post.aspx?ID=1315

/Daniel Bugday

"Kamlesh" <Kamlesh.K73@gmail.com> wrote in message
news:1183118067.109797.144470@j4g2000prf.googlegroups.com...
> 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)
>


Re: Search In document Library by Kamlesh

Kamlesh
Fri Jun 29 08:11:27 CDT 2007

On Jun 29, 5:15 pm, "Daniel Bugday" <itkons...@gmail.com> wrote:
> Have your tried the CAML Query builder?
>
> http://www.u2u.info/Blogs/Patrick/Lists/Posts/Post.aspx?ID=3D1315
>
> /Daniel Bugday
>
> "Kamlesh" <Kamlesh....@gmail.com> wrote in message
>
> news:1183118067.109797.144470@j4g2000prf.googlegroups.com...
>
>
>
> > 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 =3D SPContext.Current.Web;
>
> > #region Using SPGridView to display contents of one list
>
> > SPList list =3D web.Lists["assignments"];
> > //generateGrid(spGrid, list.Items.GetDataTable().DefaultView);
>
> > #endregion
>
> > #region Using SPGridView to display contents of several lists
> > SPWeb rootWeb =3D SPContext.Current.Site.RootWeb;
> > SPSiteDataQuery query =3D new SPSiteDataQuery();
>
> > //look through all webs
> > query.Webs =3D "<Webs Scope=3D\"Recursive\">";
> > //only look through tasks lists
> > query.Lists =3D "<Lists ServerTemplate=3D\"107\" />";
> > query.ViewFields =3D "<FieldRef Name=3D\"Title\" />"
> > + "<FieldRef Name=3D\"StartDate\" /><FieldRef Name=3D\"DueDa=
te
> > \" />";
>
> > //get only the items where the start date is greater than
> > 7/01/2006
> > query.Query =3D String.Format("<Where><Gt><FieldRef
> > Name=3D'StartDate'/>" +
> > "<Value Type=3D'DateTime' StorageTZ=3D'TRUE'>{0}</Value>=
</
> > Gt></Where>",
>
> > SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.UtcNow.AddDa=
ys(-=AD5)));
>
> > DataTable dt =3D rootWeb.GetSiteData(query);
> > DataView dv =3D new DataView(dt);
> > generateGrid(spGridCrossWeb, dv);
> > #endregion
>
> > }
>
> > protected void generateGrid(SPGridView spGrid, DataView dv)
> > {
> > SPBoundField boundField =3D new SPBoundField();
> > boundField.HeaderText =3D "Title";
> > boundField.DataField =3D "Title";
> > spGrid.Columns.Add(boundField);
>
> > boundField =3D new SPBoundField();
> > boundField.HeaderText =3D "Start Date";
> > boundField.DataField =3D "StartDate";
> > spGrid.Columns.Add(boundField);
>
> > boundField =3D new SPBoundField();
> > boundField.HeaderText =3D "Due Date";
> > boundField.DataField =3D "DueDate";
> > spGrid.Columns.Add(boundField);
>
> > spGrid.DataSource =3D dv;
> > spGrid.DataBind();
> > }
>
> > }
>
> > Please send me solution or any other code to seach contents in
> > Dcoument Library
>
> > Regards,
>
> > Kamlesh ( kamlesh....@gmail.com)- Hide quoted text -
>
> - Show quoted text -

Daniel

Thanx for reply but it didnt work.

Regards,

Kamlesh