In MOSS , to query a document library which has sub folders.You need to set the ViewAttributes property of the SPQuery object to Scope="Recursive"
The following code illustrates the same.
SPSite site = new SPSite(");
SPWeb web = site.OpenWeb();
SPList lst = web.Lists["testDocu"];
SPQuery qry = new SPQuery();
qry.Query =" <Query> <Where> <Lt> <FieldRef Name=\"Created\" /> <Value IncludeTimeValue=\"TRUE\" Type=\"DateTime\"> 2011-03-11T00:23:43Z </Value> </Lt> </Where> < /Query> ";
qry.ViewAttributes = "Scope=\"Recursive\"";
SPListItemCollection itmcln = lst.GetItems(qry);
foreach (SPListItem itm in itmcln)
{
Console.WriteLine(itm.Name.ToString());
}
The following code illustrates the same.
SPSite site = new SPSite(");
SPWeb web = site.OpenWeb();
SPList lst = web.Lists["testDocu"];
SPQuery qry = new SPQuery();
qry.Query =" <Query> <Where> <Lt> <FieldRef Name=\"Created\" /> <Value IncludeTimeValue=\"TRUE\" Type=\"DateTime\"> 2011-03-11T00:23:43Z </Value> </Lt> </Where> < /Query> ";
qry.ViewAttributes = "Scope=\"Recursive\"";
SPListItemCollection itmcln = lst.GetItems(qry);
foreach (SPListItem itm in itmcln)
{
Console.WriteLine(itm.Name.ToString());
}
No comments:
Post a Comment