I have a document library which has a two level hierarchy of folders.I have to get the latest week.pdf which is added in Folder2/latest month(every month they add new folder in Folder2 and they add new week.pdf every week).I have tried to get that using server object model,but couldn't.
I am able to get the latest document from all the folders with in the document library using the following code.But I have to get the latest doc from the nested folders.
using (SPSite site = new SPSite(SPContext.Current.Web.Url))
{
using (SPWeb web = site.OpenWeb())
{
int id = 0;
SPList items = web.Lists["Resources"];
SPQuery query = new SPQuery();
String camlquery = "<Where><Geq><FieldRef Name='Created' /><Value IncludeTimeValue='FALSE' Type='DateTime'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Now) + "</Value></Geq></And></Where>";
query.ViewAttributes =
"Scope = 'Recursive'";
query.ViewFields =
"<FieldRef Name='Created' /><FieldRef Name='Title' /><FieldRef Name='Name' />";
query.Query = camlquery;
query.RowLimit = 1;
SPListItemCollection ic = items.GetItems(query);
//Some code here
}
}