Following  is the code which will demonstrate to get the list of documents that have been uploaded to the sharepoint web application by specifying the date values as the filter values.The following code will only get the documents uploaded in Shared Documents library of the entire web application  

protected void Page_Load(object sender, EventArgs e)
         {
 
            SPWebApplication spWebApplication = SPContext.Current.Web.Site.WebApplication;
             List<SPListItemCollection> lstSPListItemCollection = new List<SPListItemCollection>();
             foreach (SPSite site in spWebApplication.Sites)
             {
                 foreach (SPWeb web in site.AllWebs)
                 {
                     if (!web.IsRootWeb)
                         continue;
                     foreach (SPList list in web.Lists)
                     {
                         if (list.Title.Equals("Shared Documents")
                             && list.BaseType.Equals(SPBaseType.DocumentLibrary) && list.BaseTemplate.Equals(SPListTemplateType.DocumentLibrary))
                         {
                             SPQuery qry = new SPQuery();
                             qry.Query = @"<Where>
                                                 <And>
                                                     <Geq>
                                                     <FieldRef Name='Created' />
                                                     <Value Type='DateTime'>2013-01-30T12:00:00Z</Value>
                                                     </Geq>
                                                     <Eq>
                                                     <FieldRef Name='FSObjType' />
                                                     <Value Type='Integer'>0</Value>
                                                     </Eq>
                                                 </And>
                                             </Where>
                                             <OrderBy>
                                                 <FieldRef Name='Title' />
                                                 <FieldRef Name='Created' />
                                                 <FieldRef Name='Author' />
                                                 <FieldRef Name='Modified' />
                                                 <FieldRef Name='Editor' />
                                                 <FieldRef Name='FileRef' />
                                             </OrderBy>";
                             qry.ViewAttributes = "Scope='RecursiveAll'";
                             SPListItemCollection spListItemCollection = list.GetItems(qry);
                             lstSPListItemCollection.Add(spListItemCollection);
 
                        }
 
                    }
 
                }
 
            }
 
            if (lstSPListItemCollection.Count > 0)
                 BindToGrid(lstSPListItemCollection);
         }
 
        private void BindToGrid(List<SPListItemCollection> lstSPListItemCollection)
         {
             
             DataRow row;
             DataTable table = new DataTable();
             table.Columns.Add("Name", typeof(string));
             table.Columns.Add("Created", typeof(string));
             table.Columns.Add("URL", typeof(string));
             table.Columns.Add("Createdby", typeof(string));
             foreach (SPListItemCollection spListItemCollection in lstSPListItemCollection)
             {
                 foreach (SPListItem spListItem in spListItemCollection)
                 {
                     row = table.Rows.Add();
                     row["Name"] = spListItem["Name"].ToString();
                     row["URL"] = spListItem["FileRef"].ToString();
                     row["Created"] = spListItem["Created"].ToString();
                     row["Createdby"]=spListItem["Created_x0020_By"].ToString();
                 }
 
            }
             SPBoundField boundField;
             boundField = new SPBoundField();
             boundField.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
             boundField.ItemStyle.Wrap = false;
             boundField.HeaderText = "Name";
             boundField.DataField = "Name";
             gvRecentDocuments.Columns.Add(boundField);
             boundField = new SPBoundField();
             boundField.HeaderText = "Created";
             boundField.DataField = "Created";
             gvRecentDocuments.Columns.Add(boundField);
             boundField = new SPBoundField();
             boundField.HeaderText = "URL";
             boundField.DataField = "URL";
             gvRecentDocuments.Columns.Add(boundField);
             boundField = new SPBoundField();
             boundField.HeaderText = "Createdby";
             boundField.DataField = "Createdby";
             gvRecentDocuments.Columns.Add(boundField);
             gvRecentDocuments.DataSource = table.DefaultView;
             gvRecentDocuments.DataBind();
 
        }


Other Languages

This article is also available in the following languages: