public void CanConstructQueryWithMultipleFields() { CAMLQueryBuilder target = new CAMLQueryBuilder(); target.AddEqual("Name", "Value"); target.AddEqual("Name2", "Value2"); SPQuery query = target.Build(); Assert.AreEqual("<Where><And><Eq><FieldRef Name='Name'/><Value Type='Text'>Value</Value></Eq><Eq><FieldRef Name='Name2'/><Value Type='Text'>Value2</Value></Eq></And></Where>", query.Query); }
/// <summary> /// Retrieve the configuration for the specified business event. /// </summary> /// <param name="businessEvent">The business event to get the configuration for</param> /// <returns>The business event's configuration. </returns> public BusinessEventTypeConfiguration GetBusinessEventTypeConfiguration(string businessEvent) { IHierarchicalConfig hierarchicalConfig = SharePointServiceLocator.Current.GetInstance <IHierarchicalConfig>(); string adminWebUrl = hierarchicalConfig.GetByKey <string>(Constants.SubSiteCreationConfigSiteKey, ConfigLevel.CurrentSPFarm); if (string.IsNullOrEmpty(adminWebUrl)) { throw new SubSiteCreationException(string.Format(CultureInfo.CurrentCulture, ConfigSiteNotFoundMessage, Constants.SubSiteCreationConfigSiteKey)); } using (SPSite site = new SPSite(adminWebUrl)) { using (SPWeb adminWeb = site.OpenWeb()) { SPList businessEventSiteTemplateList = adminWeb.Lists[Constants.BusinessEventTypeConfigListName]; CAMLQueryBuilder camlQueryBuilder = new CAMLQueryBuilder(); camlQueryBuilder.AddEqual(FieldIds.BusinessEventFieldId, businessEvent); SPListItemCollection items = businessEventSiteTemplateList.GetItems(camlQueryBuilder.Build()); if (items.Count > 0) { return(ListItemFieldMapper.CreateEntity(items[0])); } else { throw new SubSiteCreationException(string.Format(CultureInfo.CurrentCulture, ConfigDataNotFoundMessage, businessEvent)); } } } }
public void loadData(uint startRow, uint maxRows) { var repository = new IssueTrackingRepository(view.ViewFields.Select(f => f.Id)); var queryBuilder = new CAMLQueryBuilder(); if (!string.IsNullOrEmpty(view.Status)) { queryBuilder.AddEqual(SPBuiltInFieldName.IssueStatus, view.Status); } var queryString = queryBuilder.Build(); var table = repository.Get(queryString, startRow, maxRows); table.Columns.Add("Title"); table.Columns.Add("Identity"); table.Columns.Add("NavigateUrl"); foreach (DataRow row in table.Rows) { using (SPWeb web = Web.Site.OpenWeb(new Guid(row["WebId"].ToString()))) { row["Title"] = row[view.ViewFields.FirstOrDefault().Id.ToString()]; row["Identity"] = new JavaScriptSerializer().Serialize( new RelatedItem() { WebId = row["WebId"].ToString(), ListId = row["ListId"].ToString(), ItemId = int.Parse(row["ID"].ToString()) }); var url = string.Format("{0}listform.aspx?ListId={1}&PageType=6&ID={2}&Source={3}", SPUtility.GetWebLayoutsFolder(web), row["ListId"], row["ID"], HttpUtility.UrlDecode(HttpContext.Current.Request.Url.PathAndQuery)); row["NavigateUrl"] = url; } } view.Items = table; }
public void CanUseIntegersAndDateTimes() { CAMLQueryBuilder target = new CAMLQueryBuilder(); target.AddEqual("Name", 1); target.AddEqual("Name2", new DateTime(2000, 11, 22)); SPQuery query = target.Build(); string expectedDateTime = SPUtility.CreateISO8601DateTimeFromSystemDateTime(new DateTime(2000, 11, 22)); string expectedQuery = string.Format( "<Where><And><Eq><FieldRef Name='Name'/><Value Type='Integer'>1</Value></Eq>" + "<Eq><FieldRef Name='Name2'/><Value Type='DateTime'>{0}</Value></Eq></And></Where>", expectedDateTime); Assert.AreEqual(expectedQuery, query.Query); }
public void CanConstructSimpleCAMLQuery() { CAMLQueryBuilder target = new CAMLQueryBuilder(); target.AddEqual("Name", "Value"); SPQuery query = target.Build(); Assert.AreEqual("<Where><Eq><FieldRef Name='Name'/><Value Type='Text'>Value</Value></Eq></Where>", query.Query); }
public void CanAddCustomEqualFilter() { CAMLQueryBuilder target = new CAMLQueryBuilder(); target.AddEqual("Name", "Test", "CustomType"); SPQuery query = target.Build(); Assert.AreEqual("<Where><Eq><FieldRef Name='Name'/><Value Type='CustomType'>Test</Value></Eq></Where>", query.Query); }
public void CanFilterUsingIdWithInt() { CAMLQueryBuilder target = new CAMLQueryBuilder(); Guid expectedGuid = Guid.NewGuid(); target.AddEqual(expectedGuid, 123); SPQuery query = target.Build(); Assert.AreEqual(string.Format("<Where><Eq><FieldRef ID='{0}'/><Value Type='Integer'>123</Value></Eq></Where>", expectedGuid.ToString()), query.Query); }
public void CanFilterUsingIdWithDateTime() { CAMLQueryBuilder target = new CAMLQueryBuilder(); Guid expectedGuid = Guid.NewGuid(); string expectedDateTime = SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.MinValue); target.AddEqual(expectedGuid, DateTime.MinValue); SPQuery query = target.Build(); Assert.AreEqual(string.Format("<Where><Eq><FieldRef ID='{0}'/><Value Type='DateTime'>{1}</Value></Eq></Where>", expectedGuid.ToString(), expectedDateTime), query.Query); }
public void CanFilterOnContentTypeAndValue() { CAMLQueryBuilder target = new CAMLQueryBuilder(); target.FilterByContentType("ContentTypeName"); target.AddEqual("Name", "Value"); SPQuery query = target.Build(); Assert.AreEqual("<Where><And><Eq><FieldRef Name='ContentType'/><Value Type='Text'>ContentTypeName</Value></Eq>" + "<Eq><FieldRef Name='Name'/><Value Type='Text'>Value</Value></Eq>" + "</And></Where>", query.Query); }
public PartnerPromotionEntity GetBySku(string sku) { CAMLQueryBuilder camlQueryBuilder = new CAMLQueryBuilder(); camlQueryBuilder.AddEqual("ProductSkuField", sku); SPListItemCollection collection = promotionsList.GetItems(camlQueryBuilder.Build()); if (collection != null && collection.Count > 0) { SPListItem firstListItem = collection[0]; PartnerPromotionEntity partnerPromotion = ListItemFieldMapper.CreateEntity(firstListItem); partnerPromotion.PromotionUrl = string.Format(CultureInfo.CurrentCulture, "{0}/{1}/{2}", promotionsWebUrl, ListName, firstListItem["LinkFilename"]); return(partnerPromotion); } return(null); }
private static SPListItem ExecutePartnertSiteDirectoryQuery(SPList siteCollectiongMappingList, string partnerId) { SPListItem itemFound = null; CAMLQueryBuilder camlQueryBuilder = new CAMLQueryBuilder(); camlQueryBuilder.AddEqual(FieldIds.PartnerFieldId, partnerId); SPQuery query = camlQueryBuilder.Build(); ILogger logger = SharePointServiceLocator.Current.GetInstance <ILogger>(); logger.TraceToDeveloper(string.Format(CultureInfo.CurrentCulture, "PartnerSiteDirectory FindPartnerMappingForCurrentPartner CAML: {0}", query.Query)); SPListItemCollection items = siteCollectiongMappingList.GetItems(query); if (items.Count > 0) { itemFound = items[0]; } return(itemFound); }