static void testing2() { CrossListQueryInfo cLQI = new CrossListQueryInfo(); CrossListQueryCache cLQC = new CrossListQueryCache(cLQI); //cLQC.GetSiteData() }
static void testing2() { CrossListQueryInfo cLQI = new CrossListQueryInfo(); CrossListQueryCache cLQC = new CrossListQueryCache(cLQI); //cLQC.GetSiteData() }
public static void ExampleOne(string siteURL) { using (SPSite site = new SPSite(siteURL)) { //Get a CbqQueryVersionInfo object from a ContentByQueryWebPart and use it to get a CrossListQueryInfo ContentByQueryWebPart cbq = new ContentByQueryWebPart(); CbqQueryVersionInfo versionInfo = cbq.BuildCbqQueryVersionInfo(); CrossListQueryInfo queryInfo = versionInfo.VersionCrossListQueryInfo; // Create a new CrossListQueryCache object with the queryInfo we just got CrossListQueryCache crossListCache = new CrossListQueryCache(queryInfo); SiteDataResults results = crossListCache.GetSiteDataResults(site, false); } }
public static void ExampleOne(string siteURL) { using (SPSite site = new SPSite(siteURL)) { //Get a CbqQueryVersionInfo object from a ContentByQueryWebPart and use it to get a CrossListQueryInfo ContentByQueryWebPart cbq = new ContentByQueryWebPart(); CbqQueryVersionInfo versionInfo = cbq.BuildCbqQueryVersionInfo(); CrossListQueryInfo queryInfo = versionInfo.VersionCrossListQueryInfo; // Create a new CrossListQueryCache object with the queryInfo we just got CrossListQueryCache crossListCache = new CrossListQueryCache(queryInfo); SiteDataResults results = crossListCache.GetSiteDataResults(site, false); } }
//GetSiteDataResults(Microsoft.SharePoint.SPSite,System.Boolean) // Returns the results of the current query on the specified site. The query will be run against // an SPList if useSpQueryOnList is set to true. Otherwise the query will be run against a site or web // This version of GetSiteDataResults uses the web url in this object's CrossListQueryInfo to determine // either the web to query against or the web of the list being queried against depending on the value // of useSpQueryOnList. public static void Testing(string siteURL) { SPSite oSite = new SPSite(siteURL); SPWeb oWeb = oSite.RootWeb; string query = string.Empty; string websQuery = string.Format("<Webs Scope=\"{0}\"/>", "None"); string lists = "<Lists ServerTemplate=\"101\"" + " ><List ID=\"4db0e78c-dd9c-45f2-8b9c-e5f602e7d0b7\" /></Lists>"; bool useList = true; //string relativeUrl = this.GetRelativeUrl(); //query = string.Format("<Where><Eq><FieldRef Name='FSObjType' /><Value Type='LookUp'>1</Value></Eq></Where>", relativeUrl); CrossListQueryInfo info = new CrossListQueryInfo(); info.Lists = lists; info.Webs = websQuery; info.Query = query; info.ViewFields = "<FieldRef Name=\"FileLeafRef\"/>"; info.WebUrl = oWeb.ServerRelativeUrl; CrossListQueryCache cache = new CrossListQueryCache(info); SiteDataResults sd = cache.GetSiteDataResults(oSite, true); }
//GetSiteDataResults(Microsoft.SharePoint.SPSite,System.Boolean) // Returns the results of the current query on the specified site. The query will be run against // an SPList if useSpQueryOnList is set to true. Otherwise the query will be run against a site or web // This version of GetSiteDataResults uses the web url in this object's CrossListQueryInfo to determine // either the web to query against or the web of the list being queried against depending on the value // of useSpQueryOnList. public static void Testing(string siteURL) { SPSite oSite = new SPSite(siteURL); SPWeb oWeb = oSite.RootWeb; string query = string.Empty; string websQuery = string.Format("<Webs Scope=\"{0}\"/>", "None"); string lists = "<Lists ServerTemplate=\"101\"" + " ><List ID=\"4db0e78c-dd9c-45f2-8b9c-e5f602e7d0b7\" /></Lists>"; bool useList = true; //string relativeUrl = this.GetRelativeUrl(); //query = string.Format("<Where><Eq><FieldRef Name='FSObjType' /><Value Type='LookUp'>1</Value></Eq></Where>", relativeUrl); CrossListQueryInfo info = new CrossListQueryInfo(); info.Lists = lists; info.Webs = websQuery; info.Query = query; info.ViewFields = "<FieldRef Name=\"FileLeafRef\"/>"; info.WebUrl = oWeb.ServerRelativeUrl; CrossListQueryCache cache = new CrossListQueryCache(info); SiteDataResults sd = cache.GetSiteDataResults(oSite, true); }
private void SPCrossListQeuryInfo_Click(object sender, EventArgs e) { using (SPSite _site = new SPSite("http://home/")) { using (SPWeb _web = _site.OpenWeb()) { CrossListQueryInfo query = new CrossListQueryInfo(); query.RowLimit = 100; query.WebUrl = _web.ServerRelativeUrl; query.Query = "<Where><Neq><FieldRef Name=\"ContentType\" /><Value Type=\"Text\"></Value></Neq></Where>"; //////////////////////////////////////// /////// ------------------------- ////// /////// BaseType Value ////// /////// ------------------------- ////// /////// Generic List 0 ////// /////// Document Library 1 ////// /////// Discussion Board 3 ////// /////// Survey 4 ////// /////// Issue 5 ////// //////////////////////////////////////// // Search in doclibs only query.Lists = "<Lists BaseType='1' />"; // Only .doc files query.Query = @"<Where> <Eq> <FieldRef Name='DocIcon' /> <Value Type='Computed'>docx</Value> </Eq> </Where>"; // Select only needed columns: file reference query.ViewFields = "<FieldRef Name='FileRef' />"; // Search in all webs of the site collection query.Webs = "<Webs Scope='SiteCollection' />"; CrossListQueryCache cache = new CrossListQueryCache(query); // Perform the query DataTable table = cache.GetSiteData(_web); // Generate an absolute url for each document foreach (DataRow row in table.Rows) { string relativeUrl = row["FileRef"].ToString().Substring( row["FileRef"].ToString().IndexOf("#") + 1); string fullUrl = _site.MakeFullUrl(relativeUrl); // Write urls to console MessageBox.Show(fullUrl); } } } }
protected void SearchButton_Click(object sender, EventArgs e) { var searchTitle = TitleSearch.Text; var searchDescription = DescriptionSearch.Text; var searchPageCount = PagesCountSearch.Text; var searchTitleTemplate = $"<Contains><FieldRef Name='Title'></FieldRef><Value Type='Text'>{searchTitle}</Value></Contains>"; var searchDescriptionTemplate = $"<Contains><FieldRef Name='Announcement'></FieldRef><Value Type='Text'>{searchDescription}</Value></Contains>"; var searchPageCountTemplate = $"<Eq><FieldRef Name='PagesCount'></FieldRef><Value Type='Number'>{searchPageCount}</Value></Eq>"; var propsSearchArr = new Stack(); var totalSearchParamsCount = 0; if (!string.IsNullOrEmpty(searchTitle)) { totalSearchParamsCount++; propsSearchArr.Push(searchTitleTemplate); } if (!string.IsNullOrEmpty(searchDescription)) { totalSearchParamsCount++; propsSearchArr.Push(searchDescriptionTemplate); } if (!string.IsNullOrEmpty(searchPageCount)) { totalSearchParamsCount++; propsSearchArr.Push(searchPageCountTemplate); } var camlQuery = string.Concat("<Where>", totalSearchParamsCount > 0 ? "<And>" : "", totalSearchParamsCount > 1 ? "<And>" : "", "<BeginsWith>", "<FieldRef Name='ContentTypeId'></FieldRef>", "<Value Type='ContentTypeId'>", searchContentType, "</Value>", "</BeginsWith>", totalSearchParamsCount > 0 ? propsSearchArr.Pop() : "", totalSearchParamsCount > 0 ? "</And>" : "", totalSearchParamsCount > 2 ? "<And>" : "", totalSearchParamsCount > 1 ? propsSearchArr.Pop() : "", totalSearchParamsCount > 2 ? propsSearchArr.Pop() : "", totalSearchParamsCount > 1 ? "</And>" : "", totalSearchParamsCount > 2 ? "</And>" : "", "</Where>", "<OrderBy>", "<FieldRef Name='Modified' Ascending='FALSE' />", "</OrderBy>"); var siteQuery = new CrossListQueryInfo(); siteQuery.Lists = listsSearch; siteQuery.Query = camlQuery; siteQuery.ViewFields = viewFieldsSearch; siteQuery.Webs = websSearch; siteQuery.UseCache = false; var siteQueryCache = new CrossListQueryCache(siteQuery); var results = siteQueryCache.GetSiteData(SPContext.Current.Site); foreach (DataRow row in results.Rows) { row["PagesCount"] = row["PagesCount"].ToString().Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries)[0]; } for (var i = results.Columns.Count - 1; i >= 0; i--) { switch (results.Columns[i].ColumnName) { case "Title": case "Announcement": case "PagesCount": break; default: results.Columns.RemoveAt(i); break; } } ResultDocuments.DataSource = results; ResultDocuments.DataBind(); }