[Home] [Recent] [Site Map] [SharePoint] [XBOX]
I will take an example of searching files added in last 7 days in 'document library.
using (SPWeb web = SPContext.Current.Web) //Best practice to use SPWeb in using.
{
DataTable dt;
SPSiteDataQuery Query = new SPSiteDataQuery(); //Instantiate SPSiteDataQuery
//Date value in CAML query is accepted in a specific format. Below is the format accepted.
string str7DaysBackDateTime = (DateTime.Now.Add(new TimeSpan(-7, 0, 0, 0, 0))).ToString("yyyy-MM-ddThh:mm:ssZ");
string strQuery = String.Format("<Where><Gt><FieldRef Name=\"Modified\" />"
+"<Value Type=\"DateTime\">{0}</Value></Gt></Where>"
+"<OrderBy><FieldRef Ascending=\"FALSE\" Name=\"Modified\"/></OrderBy>"
, str7DaysBackDateTime);
Query.Query = strQuery; //Assign CAML query(without <Query> tag.
Query.RowLimit = 15; //Max Number of rows you want in the result.
StringBuilder sb = new StringBuilder();
sb.Append("<Lists>");
foreach (SPList list in web.Lists)
{
if (list.BaseType == SPBaseType.DocumentLibrary)
{
sb.Append("<List ID=\"" + list.ID.ToString() + "\"/>");
}
}
sb.Append("</Lists>");
Query.Lists = sb.ToString(); //The lists on which you want your query to be run.
dt = web.GetSiteData(Query);
}
I guess the above code is selft explanatory and is having enough comments also to explain the things.
akhilesh tiwari
Site List:
>>Xbox Live_s Major Nelson
>>Xbox 360 & SharePoint 2007 Weblog
>>Carsten Keutmann_s Blog
>>Mohamed Zaki_s Blog [Sharepoint MVP]
>>The Mit_s Blog
>>Mart Muller_s Sharepoint Weblog
>>Microsoft SharePoint Products and Technologies Team Blog
>>SharePoint Solutions Blog
>>4GuysFromRolla.com Headlines
>>ASP.NET Blogs
>>SharePoint Blogs
>>SharePoint Blogs
>>Joel on Software
>>ADO Guy_s Rants and Raves
>>Microsoft Live Labs
>>GadgetNews
>>Windows Vista Team Blog
>>VoIP & Gadgets Blog
>>schrankmonster blog
>>Via Virtual Earth Blog
>>Feed
>>MSDN Blogs
>>Mashable!
Links:
Jack's Readings
Month Archives:
Oct 2007
Sep 2007
Top Tags:
social software social networking .NET mashable Sharepoint ASP.NET Web 2.0 Web2.0 Startups Community News Search Marketplace General Software Development AJAX Windows Vista Visual Studio Microsoft myspace Silverlight People Powered! YouTube Vista MOSS Featured News C# Events MOSS 2007 Google WPF Office 2007 Web Community Security General Personal Xbox 360 facebook Tools development SharePoint 2007 Fun Atlas Architecture ASP.NET AJAX myspace codes TheLongTail IIS SQL Server Developers Revenue Sharing Video Pictures WCF Mobile 2.0 Announcements Orcas MIX07 Arcade Team System JavaScript News
@2007 All rights Reserved |