private void createItem(string data, int increment) { string[] dataArray = data.Split(';'); Item parentItem = ScConstants.SitecoreDatabases.MasterDb.GetItem(Templates.DoctorList.ID); //Set the parent item using (new SecurityDisabler()) { string itemName = dataArray[0]; //or set appropriate item name Item addedItem = parentItem.Add(itemName, new TemplateID(Templates.Doctor.IDPageType)); addedItem.Editing.BeginEdit(); addedItem[Templates.Person.Fields.Name] = dataArray[1]; addedItem[Templates.Person.Fields.Title] = dataArray[2]; Sitecore.Data.Items.MediaItem image = ScConstants.SitecoreDatabases.MasterDb.GetItem("/sitecore/media library/Cemedi/FotoMedici/" + (dataArray[4].Split('.'))[0]); if (image != null) { Sitecore.Data.Fields.ImageField imagefield = addedItem.Fields[Templates.Person.Fields.Picture]; imagefield.Alt = image.Alt; imagefield.MediaID = image.ID; } addedItem[Templates.Person.Fields.Summary] = dataArray[5]; addedItem[Templates.Person.Fields.Surname] = dataArray[0]; addedItem[Templates.Doctor.Fields.Specialist] = dataArray[3]; addedItem[Templates.Doctor.Fields.Activities] = dataArray[6]; addedItem[Templates.Doctor.Fields.Hospital] = dataArray[7]; addedItem.Editing.EndEdit(); } }
public static List <UserBadgeModel> GetUserBadges(string username) { string imageUrl = String.Empty; List <UserBadgeModel> badges = new List <UserBadgeModel>(); if (!String.IsNullOrEmpty(username)) { string points = TelligentService.TelligentService.ReadUserPoints(username); //Search sitecore based on templateid and points Item[] currItems = Sitecore.Context.Database.SelectItems("fast:/sitecore/content/Globals//*[@@templateid = '" + UserBadgeModel.TemplateID + "' and @Number of Points Range Low >='" + points + "' and @Number of Points Range High <='" + points + "']"); ///TODO: overload or modify to use different logic to return the list of userbadges foreach (var item in currItems) { UserBadgeModel badge = new UserBadgeModel(); // Item item = currItems.OrderBy(x => Convert.ToInt32(x.Fields["Number of Points"].ToString())).First<Item>(); Sitecore.Data.Fields.ImageField imgField = ((Sitecore.Data.Fields.ImageField)item.Fields["Points Icon"]); string url = Sitecore.Resources.Media.MediaManager.GetMediaUrl(imgField.MediaItem); badge.ImageUrl = url;//item.Fields["Points Icon"].ToString(); badge.Name = item.DisplayName; badge.Points_Low = Convert.ToInt32(item.Fields["Number of Points Range Low"].ToString()); badge.Point_High = Convert.ToInt32(item.Fields["Number of Points Range High"].ToString()); badges.Add(badge); } } return(badges); }
protected void setupNormalView() { if (myDataSourceItem == null) { return; } foreach (Item img in myDataSourceItem.Children) { if (img.TemplateName == "GalleryImage") { Sitecore.Data.Fields.ImageField imgFld = (Sitecore.Data.Fields.ImageField)img.Fields["image"]; if (imgFld != null && imgFld.MediaItem != null) { Sitecore.Data.Items.MediaItem image = new Sitecore.Data.Items.MediaItem(imgFld.MediaItem); string title = ""; if (!string.IsNullOrEmpty(img["title"])) { title = img["title"].ToString(); } imageObjects.Text += "<li><a class='photo-grid-item' data-toggle='lightbox' data-gallery='gallery' data-parent='.photo-grid' data-title= '" + title + "' title='" + title + "'href='" + Sitecore.StringUtil.EnsurePrefix('/', Sitecore.Resources.Media.MediaManager.GetMediaUrl(image)) + "'>" + title + "</a></li>"; } } } }
public static string GetImageUrl(this CustomImageField customImageField, int?width = null, int?height = null, int?maxWidth = null, int?maxHeight = null) { string imageUrl = ""; Sitecore.Data.Fields.ImageField imageField = customImageField.Field; if (imageField != null && imageField.MediaItem != null) { var image = new MediaItem(imageField.MediaItem); var options = new MediaUrlOptions { Width = width.HasValue ? width.Value : Int32.Parse(imageField.Width), Height = height.HasValue ? height.Value : Int32.Parse(imageField.Height) }; if (maxWidth.HasValue) { options.MaxWidth = maxWidth.Value; } if (maxHeight.HasValue) { options.MaxHeight = maxHeight.Value; } imageUrl = Sitecore.StringUtil.EnsurePrefix('/', MediaManager.GetMediaUrl(image, options)); } return(imageUrl); }
// GET: Product public ActionResult ProductCallout() { // var product = Sitecore.Context.Database.GetItem("sitecore/Content/Home/ProductPage"); Item currentpage = Sitecore.Context.Item; var product = currentpage; Sitecore.Data.Fields.MultilistField productList = product.Fields["ProductCalloutList"]; Item[] Products = productList.GetItems(); var productCallouts = new List <ProductCallout>(); foreach (Item ProductItem in Products) { ProductCallout product1 = new ProductCallout(); product1.ProductTitle = ProductItem.Fields[Templates.ProductCallout.Fields.ProductCalloutTitle].Value; Sitecore.Data.Fields.LinkField link = ProductItem.Fields[Templates.ProductCallout.Fields.ProductCalloutLink]; if (link.LinkType == "internal") { product1.ProductLink = Sitecore.Links.LinkManager.GetItemUrl(link.TargetItem); } else { product1.ProductLink = link.Url; } Sitecore.Data.Fields.ImageField imgField = ProductItem.Fields[Templates.ProductCallout.Fields.ProductCalloutImage]; string url = Sitecore.Resources.Media.MediaManager.GetMediaUrl(imgField.MediaItem); product1.ProductImage = url; product1.ProductSubTitle = ProductItem.Fields[Templates.ProductCallout.Fields.ProductCalloutSubTutle].Value; productCallouts.Add(product1); } return(View(productCallouts)); }
// GET: RelatedProduct public ActionResult RelatedProducts() { Item currentPage = Sitecore.Context.Item; Sitecore.Data.Fields.MultilistField relatedProducts = currentPage.Fields["RelatedProductList"]; Item[] Products = relatedProducts.GetItems(); var RelatedProductList = new List <ProductCallout>(); foreach (Item ProductItem in Products) { ProductCallout product1 = new ProductCallout(); product1.ProductTitle = ProductItem.Fields[Templates.ProductCallout.Fields.ProductCalloutTitle].Value; Sitecore.Data.Fields.LinkField link = ProductItem.Fields[Templates.ProductCallout.Fields.ProductCalloutLink]; if (link.LinkType == "internal") { product1.ProductLink = Sitecore.Links.LinkManager.GetItemUrl(link.TargetItem); } else { product1.ProductLink = link.Url; } Sitecore.Data.Fields.ImageField imgField = ProductItem.Fields[Templates.ProductCallout.Fields.ProductCalloutImage]; string url = Sitecore.Resources.Media.MediaManager.GetMediaUrl(imgField.MediaItem); product1.ProductImage = url; product1.ProductSubTitle = ProductItem.Fields[Templates.ProductCallout.Fields.ProductCalloutSubTutle].Value; RelatedProductList.Add(product1); } return(View(RelatedProductList)); }
private void RenderPdfContent() { if (this.dataSourceItem["Button Image"] != null) { Sitecore.Data.Fields.ImageField imgField = ((Sitecore.Data.Fields.ImageField)dataSourceItem.Fields["Button Image"]); btnPdfView.ImageUrl = Sitecore.Resources.Media.MediaManager.GetMediaUrl(imgField.MediaItem); } }
private static Dictionary <string, string> GetFieldHtmls(Item item, List <string> FieldNames) { Assert.ArgumentNotNull(item, "item"); Assert.ArgumentNotNullOrEmpty(RenderFieldPipelineName, "renderField"); Dictionary <string, string> argsResult = new Dictionary <string, string>(); foreach (var fieldName in FieldNames) { if (item == null) { return(argsResult); } RenderFieldArgs args = new RenderFieldArgs { Item = item, FieldName = fieldName }; CorePipeline.Run(RenderFieldPipelineName, args); if (!args.Result.IsEmpty) { string contents = args.Result.ToString(); string multilistItems = ""; // Image Field Type - Get only image path if (args.FieldTypeKey == "image") { Sitecore.Data.Fields.ImageField iFld = args.Item.Fields[fieldName]; Sitecore.Resources.Media.MediaUrlOptions opt = new Sitecore.Resources.Media.MediaUrlOptions(); //opt.AlwaysIncludeServerUrl = true; opt.AbsolutePath = true; string mediaUrl = Sitecore.Resources.Media.MediaManager.GetMediaUrl(iFld.MediaItem, opt); contents = mediaUrl; } // Multilist Field Type - Convert Item ID to Item Name if (args.FieldTypeKey == "multilist") { List <string> itemId = args.Result.ToString().Split('|').ToList(); int count = 1; foreach (string i in itemId) { Item theItem = item.Database.GetItem(Sitecore.Data.ID.Parse(i)); if (theItem != null) { multilistItems += theItem.Name; if (count != itemId.Count) { multilistItems += "|"; } } count++; } contents = multilistItems; } argsResult.Add(fieldName, contents); } } return(argsResult); }
private void BuildProducts() { Sitecore.Data.Database database = Sitecore.Data.Database.GetDatabase("web"); Sitecore.Data.Items.Item[] Productsitems = database.SelectItems("fast:/sitecore/content/home//*[@@templateid='{2EE70A6B-AF13-498E-8419-BDA52C8C05DD}']"); foreach (var Product in Productsitems) { var item = Context.Database.GetItem(Product.ID); var attributes = new List <XElement>(); if (!string.IsNullOrEmpty(Product.Fields["EanBarcode"].Value)) { XAttribute[] familyAttributes = { new XAttribute("id", "BV_FE_FAMILY") }; XAttribute[] expandAttributes = { new XAttribute("id", "BV_FE_EXPAND") }; attributes.Add(new XElement(Bv + "Attribute", familyAttributes, new XElement(Bv + "Value", Product.Fields["EanBarcode"].Value))); attributes.Add(new XElement(Bv + "Attribute", expandAttributes, new XElement(Bv + "Value", "BV_FE_FAMILY:" + Product.Fields["EanBarcode"].Value))); } var productdesc = RemoveHTMLTags(Product.Fields["ProductIntroduction"].Value); var desc = !ExtensionMethods.IsNullOrEmpty(productdesc) ? new XCData(productdesc) : new XCData(""); var options = Sitecore.Links.LinkManager.GetDefaultUrlOptions(); options.LanguageEmbedding = Sitecore.Links.LanguageEmbedding.Never; var productUrl = LinkManager.GetItemUrl(item, options); var catExternalId = item.Parent.ParentID.ToShortID().ToString(); if (catExternalId.IsNullOrEmpty()) { continue; } var brandExternalId = item.ParentID.ToShortID().ToString();; string ImageUrl = string.Empty; Sitecore.Data.Fields.ImageField imageField = item.Fields["ReferenceImage"]; if (imageField != null && imageField.MediaItem != null) { Sitecore.Data.Items.MediaItem image = new Sitecore.Data.Items.MediaItem(imageField.MediaItem); ImageUrl = Sitecore.StringUtil.EnsurePrefix('/', Sitecore.Resources.Media.MediaManager.GetMediaUrl(image)); } //Add a single product var prod = new XElement(Bv + "Product"); prod.Add(new XElement(Bv + "ExternalId", Product.Fields["EanBarcode"].Value)); prod.Add(new XElement(Bv + "Name", new XCData(Product.Fields["__Display Name"].Value))); prod.Add(new XElement(Bv + "Description", desc)); prod.Add(new XElement(Bv + "CategoryExternalId", catExternalId)); prod.Add(new XElement(Bv + "ProductPageUrl", GetFullUrl(productUrl))); prod.Add(new XElement(Bv + "ImageUrl", GetFullUrl(ImageUrl))); prod.Add(new XElement(Bv + "EANs", new XElement(Bv + "EAN", Product.Fields["EanBarcode"].Value))); prod.Add(new XElement(Bv + "Attributes", attributes)); if (!string.IsNullOrEmpty(brandExternalId)) { prod.Add(new XElement(Bv + "BrandExternalId", brandExternalId)); } Products.Add(prod); } }
public static Sitecore.Data.Fields.ImageField getImgField(Item parentItem, string fieldName) { try { Sitecore.Data.Fields.ImageField iFld = parentItem.Fields[fieldName]; return(iFld); } catch { return(null); } }
protected void Page_Load(object sender, EventArgs e) { Item currentItem = Sitecore.Context.Item; if (currentItem.Fields["Image"] != null && !string.IsNullOrEmpty(currentItem.Fields["Image"].Value)) { ImageField currentImageField = currentItem.Fields["Image"]; Item imageItem = currentImageField.MediaItem; litImageTitle.Text = imageItem.Fields["Title"].Value; } }
public static Image Source() { var dataSourceId = RenderingContext.CurrentOrNull.Rendering.DataSource; var dataSource = Sitecore.Context.Database.GetItem(dataSourceId); Sitecore.Data.Fields.ImageField imi = dataSource.Fields["Image"]; var image = new MediaItem(imi.MediaItem); return(new Image() { Src = MediaManager.GetMediaUrl(image) }); }
private string GetImageUrl() { var currentItem = Sitecore.Context.Item; var imageUrl = string.Empty; Sitecore.Data.Fields.ImageField imageField = InnerItem.Fields["CarouselImage"]; if (imageField?.MediaItem != null) { var image = new MediaItem(imageField.MediaItem); imageUrl = StringUtil.EnsurePrefix('/', MediaManager.GetMediaUrl(image)); } return(imageUrl); }
public static string GetImageFieldURL(this Item source, string fieldName) { Sitecore.Data.Fields.ImageField imgField = (Sitecore.Data.Fields.ImageField)source.Fields[fieldName]; if (imgField != null && imgField.MediaItem != null) { MediaItem image = new MediaItem(imgField.MediaItem); if (image != null) { return(SitecoreUtil.GetMediaUrlWithServer(image)); } } return(string.Empty); }
protected override void DoRender(HtmlTextWriter output) { Sitecore.Data.Items.Item item = Sitecore.Context.Item; if (item == null) { return; } Sitecore.Data.Fields.ImageField field = item.Fields["Logo"]; if (field == null || field.MediaItem == null) { return; } string icon = Sitecore.StringUtil.EnsurePrefix('/', field.MediaItem.Appearance.Icon); output.WriteLine(String.Format( @"Icon: <img src=""{0}""><br />", icon)); string thumbnail = Sitecore.StringUtil.EnsurePrefix( '/', Sitecore.Resources.Media.MediaManager.GetThumbnailUrl(field.MediaItem)); output.WriteLine(String.Format( @"Thumbnail: <img src=""{0}""><br />", thumbnail)); Sitecore.Resources.Media.MediaUrlOptions options = new Sitecore.Resources.Media.MediaUrlOptions { Database = field.MediaItem.Database, Language = field.MediaItem.Language, Version = field.MediaItem.Version, DisableBrowserCache = true, BackgroundColor = Color.DarkGreen, Height = 100, Width = 100, AllowStretch = true, }; string url = Sitecore.StringUtil.EnsurePrefix('/', Sitecore.Resources.Media.MediaManager.GetMediaUrl(field.MediaItem, options)); output.WriteLine(String.Format( @"Stretch: <img src=""{0}""><br />", url)); }
private Item CreateDefaultLanguageItem(string itemName, Dictionary <string, string> fieldsToUpdate, Item newItem, TemplateItem template, Item parentItem) { // Add the item to the site tree newItem = parentItem.Add(RemoveSpecialCharacters(itemName.Trim()), template); //addVersion. // Set the new item in editing mode // Fields can only be updated when in editing mode // (It's like the begin tarnsaction on a database) if (fieldsToUpdate != null) { newItem.Editing.BeginEdit(); try { // Assign values to the fields of the new item foreach (var fields in fieldsToUpdate) { if (fields.Key == "Content Thumbnail") { MediaItem mediaItem = DownloadImage(fields.Value); Sitecore.Data.Fields.ImageField image = newItem.Fields[fields.Key]; image.Src = Sitecore.Resources.Media.MediaManager.GetMediaUrl(mediaItem); image.Alt = mediaItem.Alt; image.MediaID = mediaItem.ID; } else { newItem.Fields[fields.Key].Value = fields.Value; } } // End editing will write the new values back to the Sitecore // database (It's like commit transaction of a database) newItem.Editing.EndEdit(); } catch (System.Exception ex) { // The update failed, write a message to the log Sitecore.Diagnostics.Log.Error("Could not update item " + newItem.Paths.FullPath + ": " + ex.Message, this); // Cancel the edit (not really needed, as Sitecore automatically aborts // the transaction on exceptions, but it wont hurt your code) newItem.Editing.CancelEdit(); Response.Write(newItem.Paths.FullPath); Response.Write(ex.Message); Response.End(); } } return(newItem); }
private static void UpdateSchemaProperties(IEnumerable <SchemaProperty> schemaProperties) { ItemUrlBuilderOptions urlOptions = new ItemUrlBuilderOptions { AlwaysIncludeServerUrl = true, LanguageEmbedding = LanguageEmbedding.Never }; MediaUrlBuilderOptions mediaurlOptions = new MediaUrlBuilderOptions(); mediaurlOptions.AlwaysIncludeServerUrl = true; if (schemaProperties != null) { foreach (var item in schemaProperties) { if (item.ItemScope) { UpdateSchemaProperties(item.Properties); } else { if (item.FieldType.Value == Constants.SchemaFieldTypes.CurrentItemURL) { item.FieldValue = LinkManager.GetItemUrl(Sitecore.Context.Item, urlOptions); } else if (item.FieldType.Value == Constants.SchemaFieldTypes.FromField) { item.FieldValue = Sitecore.Context.Item.Fields[item.FieldValue]?.Value; } else if (item.FieldType.Value == Constants.SchemaFieldTypes.FromParent) { item.FieldValue = Sitecore.Context.Item.Parent?.Fields[item.FieldType.Value]?.Value; } else if (item.FieldType.Value == Constants.SchemaFieldTypes.Image) { Sitecore.Data.Fields.ImageField imgField = Sitecore.Context.Item.Fields[item.FieldValue]; if (imgField != null) { var theURL = MediaManager.GetMediaUrl(imgField.MediaItem, mediaurlOptions); item.FieldValue = HashingUtils.ProtectAssetUrl(theURL); } } } } } }
public string SaveNewEvent(string parentId, EventViewModel eventToSave) { using (new Sitecore.SecurityModel.SecurityDisabler()) { try { var masterDB = Database.GetDatabase("master"); TemplateItem templateItem = masterDB.GetItem(Templates.Event.Id); var parentItem = masterDB.GetItem(new ID(parentId)); if (parentItem != null) { var eventName = $"{eventToSave.Name.Replace(@"\", "").Replace(@"/", "").Replace(@":", "").Replace(@"?", "").Replace(@"<", "").Replace(@">", "").Replace(@"|", "").Replace(@"[", "").Replace(@"]", "").Replace(@"-", "").Replace("\"", "").Replace(@"(", "").Replace(@")", "")}"; var newEvent = parentItem.Add(eventName, templateItem); newEvent.Editing.BeginEdit(); newEvent.Fields["Description"].Value = eventToSave.Description; newEvent.Fields["Capacity"].Value = eventToSave.Capacity.ToString(); newEvent.Fields["Cost"].Value = eventToSave.Cost.ToString("F"); newEvent.Fields["IsPublic"].Value = eventToSave.IsPublic ? "1" : "0"; Sitecore.Data.Fields.ImageField bannerImageField = newEvent.Fields["BannerImage"]; bannerImageField.MediaID = new ID("{2F6BB916-F5ED-4BF3-80BD-F3D068EAA52B}"); newEvent.Fields["DateAndTime"].Value = DateUtil.ToIsoDate(eventToSave.DateAndTime); newEvent.Fields["Longitude"].Value = eventToSave.Longitude.ToString(); newEvent.Fields["Latitude"].Value = eventToSave.Latitude.ToString(); newEvent.Fields["Staff"].Value = ""; newEvent.Editing.EndEdit(); PublishItem(newEvent); return(LinkManager.GetItemUrl(newEvent, new ItemUrlBuilderOptions())); } } catch (Exception e) { Console.WriteLine(e); throw; } return(null); } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (ImageFrame == null) { return; } TextBoxCoordinate.Value = WebUtil.GetQueryString("value"); string containerId = WebUtil.GetQueryString("containerId"); string fieldId = WebUtil.GetQueryString("fieldId"); Item currentItem = _masterDb.Items.GetItem(containerId); ImageField imageField = currentItem.Fields[fieldId]; if (imageField == null || string.IsNullOrWhiteSpace(imageField.Value)) { ImageFrame.Alt = "No image available"; ImageFrame.Src = "#"; return; } string imageSrc = MediaManager.GetMediaUrl( _masterDb.Items.GetItem(imageField.MediaID), new MediaUrlBuilderOptions { Database = _masterDb, DisableMediaCache = true, DisableBrowserCache = true, AllowStretch = false }); if (!string.IsNullOrWhiteSpace(imageSrc)) { imageSrc += "&usecustomfunctions=1¢ercrop=1"; } ImageFrame.Src = imageSrc; }
public SlideshowDisplayItem(Item item, string imageFieldName) { DisplayItem = item; LinkSrc = item.GetRoutePathInfo(); DataSrc = string.Empty; ThumbSrc = string.Empty; var imageField = item.Fields[imageFieldName]; if (imageField == null) { return; } var imageFieldItem = new Sitecore.Data.Fields.ImageField(imageField); var mediaItem = imageFieldItem.MediaItem; var mediaLink = Sitecore.Resources.Media.MediaManager.GetMediaUrl(mediaItem); // new Sitecore.Resources.Media.MediaUrlOptions(400, 400, false) var mediaThumbLink = Sitecore.Resources.Media.MediaManager.GetMediaUrl(mediaItem); // new Sitecore.Resources.Media.MediaUrlOptions(400, 400, false) DataSrc = mediaLink; ThumbSrc = mediaThumbLink; }
public ActionResult SectionCallout1() { var home = Sitecore.Context.Database.GetItem("sitecore/content/Home/LandingPage"); //var AllHomeCallout = HomeCalloutFolder.GetChildren(); var SectionCallouts = new List <CalloutSection>(); Sitecore.Data.Fields.MultilistField multiselectField = home.Fields["SectionCalloutListItem"]; Item[] AllSectionCallout = multiselectField.GetItems(); foreach (Item SectionCalloutItem in AllSectionCallout) { CalloutSection sectionCallout = new CalloutSection(); sectionCallout.CalloutTitle = SectionCalloutItem.Fields[Templates.SectionCallout.Fields.SectionTitle].Value; sectionCallout.CalloutSubtitle = SectionCalloutItem.Fields[Templates.SectionCallout.Fields.SectionSubtitle].Value; Sitecore.Data.Fields.LinkField link = SectionCalloutItem.Fields[Templates.SectionCallout.Fields.SectionLink]; sectionCallout.CalloutLink = link.Url; Sitecore.Data.Fields.ImageField imgField = SectionCalloutItem.Fields[Templates.SectionCallout.Fields.SectiontImage]; string url = Sitecore.Resources.Media.MediaManager.GetMediaUrl(imgField.MediaItem); sectionCallout.CalloutImage = url; SectionCallouts.Add(sectionCallout); } return(View(SectionCallouts)); }
private Item CreateAndFillItem(string itemName, Hashtable itemFieldsData, Item destionationItem, Item itemTemplate, bool nameExact) { Item result; using (new SecurityDisabler()) { try { string text = this.CheckExistingItemName(destionationItem, itemName, nameExact); if (nameExact && text == string.Empty) { if (itemName == string.Empty) { this.PageErrorMsg = "Enter album name, please"; result = null; } else { this.PageErrorMsg = "The album with name \"" + itemName + "\" already exists"; result = null; } } else { Item item = destionationItem.Add(text, new TemplateID(itemTemplate.ID)); Language[] languages = item.Languages; for (int i = 0; i < languages.Length; i++) { Language language = languages[i]; Item item2 = item.Database.GetItem(item.ID, language); if (item2.Versions.Count == 0) { item2 = item2.Versions.AddVersion(); } item2.Editing.BeginEdit(); foreach (string text2 in itemFieldsData.Keys) { string type; if ((type = item2.Fields[text2].Type) != null && type == "Image") { if (itemFieldsData[text2] is Item) { Item item3 = (Item)itemFieldsData[text2]; MediaItem mediaItem = item3; ImageField imageField = item2.Fields[text2]; imageField.Src = "~/media" + mediaItem.MediaPath + ".ashx"; imageField.MediaPath = mediaItem.MediaPath; imageField.MediaID = mediaItem.ID; imageField.Alt = "photo image"; } } else { item2[text2] = (string)itemFieldsData[text2]; } } item2.Editing.EndEdit(); } PhotoAlbumObject.PublishOneItem(item); result = item; } } catch (Exception exception) { Log.Error("Cannot create or edit the item. Possible there are invalid fieds collection", exception, this); result = null; } } return(result); }
//[HttpPost] //public ActionResult StationInformation() //{ // stationInformation_AllType modelFull = GetAllStationInformation(); // return Json(modelFull); //} //public List<Models.StationInformation> /*stationInformation_AllType*/ GetAllStationInformation() //{ // // stationInformation_AllType allType = new stationInformation_AllType(); // //allType.stationInformation_All = new List<Models.StationInformation>(); // List<Models.StationInformation> allType = new List<Models.StationInformation>(); // //Database master = Sitecore.Configuration.Factory.GetDatabase("master"); // Database DB = Sitecore.Context.Database; // Sitecore.Data.Items.Item stationInfo_Item = DB.GetItem("/sitecore/content/Home/iMap/Configuration/Station Information/"); // foreach (Sitecore.Data.Items.Item child in stationInfo_Item.Children) // { // Sitecore.Data.Fields.Field temp = child.Fields[Templates.StationInformation.StationName]; // StationInformation stationInfoAll = new StationInformation(); // stationInfoAll.stationName = child.Fields[Templates.StationInformation.StationName].ToString(); // stationInfoAll.CRSCode = child.Fields[Templates.StationInformation.CRSCode].ToString(); // //stationInfoAll.stationAddress = child.Fields[Templates.StationInformation.StationAddress].ToString(); // stationInfoAll.xPos = child.Fields[Templates.StationInformation.XPox].ToString(); // stationInfoAll.yPox = child.Fields[Templates.StationInformation.YPos].ToString(); // stationInfoAll.status = child.Fields[Templates.StationInformation.StationStatus].ToString(); // //stationInfoAll.startDate = child.Fields[Templates.StationInformation.ValidFrom];//.Value.ToString(); // //stationInfoAll.endDate = child.Fields[Templates.StationInformation.ValidTo];//.Value.ToString(); // //station status // if (stationInfoAll.status == null || stationInfoAll.status == "") // { // //default status // //stationInfoAll.statusIcon = ""; // //stationInfo.statusTitle = null; // //stationInfo.statusMessage = null; // } // else // { // Sitecore.Data.Items.Item stationStatusDetails = DB.GetItem("/sitecore/content/Home/iMap/Configuration/Station Status/" + stationInfoAll.status); // //stationInfoAll.statusIcon = stationStatusDetails.Fields[Templates.StationStatus.StationStatusIcon]; // Sitecore.Data.Fields.ImageField statusIcon = stationStatusDetails.Fields[Templates.StationStatus.StationStatusIcon]; // stationInfoAll.imageURL = Sitecore.Resources.Media.MediaManager.GetMediaUrl(statusIcon.MediaItem); // //stationInfoAll.statusTitle = stationStatusDetails.Fields[Templates.StationStatus.StationStatusTitle].Value; // //stationInfoAll.statusMessage = stationStatusDetails.Fields[Templates.StationStatus.StationStatusDetails].Value.Replace("startDate", stationInfoAll.startDate.ToString()); // //stationInfoAll.statusMessage = stationInfoAll.statusMessage.Replace("endDate", stationInfoAll.endDate.ToString()); // //Legends legendInfoAll = new Legends(); // //legendInfoAll.icon = stationStatusDetails.Fields[Templates.LegendInformation.LegendIcon]; // //legendInfoAll.imageURL = Sitecore.Resources.Media.MediaManager.GetMediaUrl(legendInfoAll.icon.MediaItem); // //legendInfoAll.subtitle = child.Fields[Templates.LegendInformation.LegendSubtitle].ToString(); // //stationInfoAll.statusTitle = stationStatusDetails.Fields[Templates.StationStatus.StationStatusTitle].ToString(); // //stationInfoAll.statusMessage = stationStatusDetails.Fields[Templates.StationStatus.StationStatusDetails].ToString(); // } // allType.Add(stationInfoAll); // } // return allType; //} public StationInformation GetStationInformation(string city) { StationInformation stationInfo = new StationInformation(); //Database master = Sitecore.Configuration.Factory.GetDatabase("master"); Database DB = Sitecore.Context.Database; Sitecore.Data.Items.Item stationInfo_Item = DB.GetItem("/sitecore/content/Home/iMap/Configuration/Station Information/" + city); if (stationInfo_Item != null) { stationInfo.stationName = stationInfo_Item.Fields[Templates.StationInformation.StationName].ToString(); stationInfo.CRSCode = stationInfo_Item.Fields[Templates.StationInformation.CRSCode].ToString(); if (stationInfo_Item.Fields[Templates.StationInformation.StationAddress].ToString() != null || stationInfo_Item.Fields[Templates.StationInformation.StationAddress].ToString() != "") { stationInfo.stationAddress = stationInfo_Item.Fields[Templates.StationInformation.StationAddress].ToString(); } stationInfo.xPos = stationInfo_Item.Fields[Templates.StationInformation.XPox].ToString(); stationInfo.yPox = stationInfo_Item.Fields[Templates.StationInformation.YPos].ToString(); stationInfo.status = stationInfo_Item.Fields[Templates.StationInformation.StationStatus].ToString(); //stationInfo.startDate = stationInfo_Item.Fields[Templates.StationInformation.ValidFrom];//.ToString(); //stationInfo.endDate = stationInfo_Item.Fields[Templates.StationInformation.ValidTo];//.Value.ToString(); Sitecore.Data.Fields.DateField startDate = stationInfo_Item.Fields[Templates.StationInformation.ValidFrom]; //.ToString(); Sitecore.Data.Fields.DateField endDate = stationInfo_Item.Fields[Templates.StationInformation.ValidTo]; //.Value.ToString(); //station status if (stationInfo.status == null || stationInfo.status == "" || (StatusValid(endDate.DateTime) || startValid(startDate.DateTime))) { //default status //stationInfo.statusIcon = null; //stationInfo.statusTitle = null; //stationInfo.statusMessage = null; } else { Sitecore.Data.Items.Item stationStatusDetails = DB.GetItem("/sitecore/content/Home/iMap/Configuration/Station Status/" + stationInfo.status); //stationInfo.statusIcon = stationStatusDetails.Fields[Templates.StationStatus.StationStatusIcon]; Sitecore.Data.Fields.ImageField statusIcon = stationStatusDetails.Fields[Templates.StationStatus.StationStatusIcon]; if (statusIcon.MediaItem != null) { stationInfo.imageURL = Sitecore.Resources.Media.MediaManager.GetMediaUrl(statusIcon.MediaItem); } stationInfo.statusTitle = stationStatusDetails.Fields[Templates.StationStatus.StationStatusTitle].ToString(); stationInfo.statusMessage = stationStatusDetails.Fields[Templates.StationStatus.StationStatusDetails].ToString(); stationInfo.statusMessage = stationStatusDetails.Fields[Templates.StationStatus.StationStatusDetails].Value.Replace("startDate", startDate.ToString()); stationInfo.statusMessage = stationInfo.statusMessage.Replace("endDate", endDate.ToString()); //Sitecore.Data.Items.Item stationStatusDetails = DB.GetItem("/sitecore/content/Home/iMap/Configuration/Station Status/" + stationInfo.status); //stationInfo.statusIcon = stationStatusDetails.Fields[Templates.StationStatus.StationStatusIcon]; //stationInfo.imageURL = Sitecore.Resources.Media.MediaManager.GetMediaUrl(stationInfo.statusIcon.MediaItem); //stationInfo.statusIcon = stationStatusDetails.Fields[Templates.StationStatus.StationStatusIcon]; //stationInfo.statusTitle = stationStatusDetails.Fields[Templates.StationStatus.StationStatusTitle].Value; //stationInfo.statusMessage = stationStatusDetails.Fields[Templates.StationStatus.StationStatusDetails].Value.Replace("startDate", stationInfo.startDate.ToString()); //stationInfo.statusMessage = stationInfo.statusMessage.Replace("endDate", stationInfo.endDate.ToString()); } } return(stationInfo); }
public List <Models.StationInformationDTO> /*stationInformation_AllType*/ GetAllStationInformation() { // stationInformation_AllType allType = new stationInformation_AllType(); //allType.stationInformation_All = new List<Models.StationInformation>(); List <Models.StationInformationDTO> allType = new List <Models.StationInformationDTO>(); //Database master = Sitecore.Configuration.Factory.GetDatabase("master"); Database DB = Sitecore.Context.Database; Sitecore.Data.Items.Item stationInfo_Item = DB.GetItem("/sitecore/content/Home/iMap/Configuration/Station Information/"); foreach (Sitecore.Data.Items.Item child in stationInfo_Item.Children) { Sitecore.Data.Fields.Field temp = child.Fields[Templates.StationInformation.StationName]; StationInformationDTO stationInfoAll = new StationInformationDTO(); stationInfoAll.stationName = child.Fields[Templates.StationInformation.StationName].ToString(); stationInfoAll.CRSCode = child.Fields[Templates.StationInformation.CRSCode].ToString(); if (child.Fields[Templates.StationInformation.StationAddress].ToString() != null || child.Fields[Templates.StationInformation.StationAddress].ToString() != "") { stationInfoAll.stationAddress = child.Fields[Templates.StationInformation.StationAddress].ToString(); } stationInfoAll.stationAddress = child.Fields[Templates.StationInformation.StationAddress].ToString(); stationInfoAll.xPos = child.Fields[Templates.StationInformation.XPox].ToString(); stationInfoAll.yPox = child.Fields[Templates.StationInformation.YPos].ToString(); stationInfoAll.status = child.Fields[Templates.StationInformation.StationStatus].ToString(); //stationInfoAll.startDate = child.Fields[Templates.StationInformation.ValidFrom];//.Value.ToString(); //stationInfoAll.endDate = child.Fields[Templates.StationInformation.ValidTo];//.Value.ToString(); //station status Sitecore.Data.Fields.DateField startDate = child.Fields[Templates.StationInformation.ValidFrom]; Sitecore.Data.Fields.DateField endDate = child.Fields[Templates.StationInformation.ValidTo]; if (stationInfoAll.status == null || stationInfoAll.status == "" || StatusValid(endDate.DateTime) || startValid(startDate.DateTime)) { //default status //stationInfo.statusIcon = null; //stationInfo.statusTitle = null; //stationInfo.statusMessage = null; } else { Sitecore.Data.Items.Item stationStatusDetails = DB.GetItem("/sitecore/content/Home/iMap/Configuration/Station Status/" + stationInfoAll.status); //stationInfoAll.statusIcon = stationStatusDetails.Fields[Templates.StationStatus.StationStatusIcon]; Sitecore.Data.Fields.ImageField statusIcon = stationStatusDetails.Fields[Templates.StationStatus.StationStatusIcon]; stationInfoAll.imageURL = Sitecore.Resources.Media.MediaManager.GetMediaUrl(statusIcon.MediaItem); //stationInfoAll.statusTitle = stationStatusDetails.Fields[Templates.StationStatus.StationStatusTitle].Value; //stationInfoAll.statusMessage = stationStatusDetails.Fields[Templates.StationStatus.StationStatusDetails].Value.Replace("startDate", stationInfoAll.startDate.ToString()); //stationInfoAll.statusMessage = stationInfoAll.statusMessage.Replace("endDate", stationInfoAll.endDate.ToString()); //Legends legendInfoAll = new Legends(); //legendInfoAll.icon = stationStatusDetails.Fields[Templates.LegendInformation.LegendIcon]; //legendInfoAll.imageURL = Sitecore.Resources.Media.MediaManager.GetMediaUrl(legendInfoAll.icon.MediaItem); //legendInfoAll.subtitle = child.Fields[Templates.LegendInformation.LegendSubtitle].ToString(); //stationInfoAll.statusTitle = stationStatusDetails.Fields[Templates.StationStatus.StationStatusTitle].ToString(); //stationInfoAll.statusMessage = stationStatusDetails.Fields[Templates.StationStatus.StationStatusDetails].ToString(); } allType.Add(stationInfoAll); } return(allType); }
private Item AddLanguageVersionItem(string posttype, string itemName, Dictionary <string, string> fieldsToUpdate, TemplateItem template, Item newItem, Sitecore.Data.Database master, string lang, string postid) { Item newLanguageVersionItem = master.GetItem(newItem.Paths.Path, Sitecore.Globalization.Language.Parse(lang)); using (new Sitecore.SecurityModel.SecurityDisabler()) { try { if (0 == newLanguageVersionItem.Versions.Count) { newLanguageVersionItem.Versions.AddVersion(); } newLanguageVersionItem.Editing.BeginEdit(); // Assign values to the fields of the new item foreach (var fields in fieldsToUpdate) { if (fields.Key == "Content Thumbnail") { MediaItem mediaItem = DownloadImage(fields.Value); Sitecore.Data.Fields.ImageField image = newLanguageVersionItem.Fields[fields.Key]; image.Src = Sitecore.Resources.Media.MediaManager.GetMediaUrl(mediaItem); image.Alt = mediaItem.Alt; image.MediaID = mediaItem.ID; } else { if (fields.Key == "Page Title") { Response.Write(postid + " | " + lang + " | <b>" + fields.Value + "</b><br/>"); } newLanguageVersionItem.Fields[fields.Key].Value = fields.Value; } string tagids = string.Empty; string source = string.Empty; switch (fields.Key) { case "Child Issues": tagids = GetTags(posttype, "child-issue", postid, ChildIssueTemplate, "Issue Name"); if (!string.IsNullOrEmpty(tagids)) { newLanguageVersionItem[fields.Key] = tagids; } break; case "Child Grades": tagids = GetTags(posttype, "grade_level", postid, ChildGradesTemplate, "Name"); if (!string.IsNullOrEmpty(tagids)) { newLanguageVersionItem[fields.Key] = tagids; } break; case "Child Diagnoses": tagids = GetTags(posttype, "child-diagnosis", postid, ChildDiagnosesTemplate, "Diagnosis Name"); if (!string.IsNullOrEmpty(tagids)) { newLanguageVersionItem[fields.Key] = tagids; } break; case "Complexity Levels": tagids = GetTags(posttype, "content-complexity", postid, ComplexityLevelsTemplate, "Complexity Name"); if (!string.IsNullOrEmpty(tagids)) { newLanguageVersionItem[fields.Key] = tagids; } break; case "Diagnosed Condition": tagids = GetTags(posttype, "diagnosed-undiagnosed", postid, DiagnosedConditionTemplate, "Diagnosis Name"); if (!string.IsNullOrEmpty(tagids)) { newLanguageVersionItem[fields.Key] = tagids; } break; case "Applicable Interests": tagids = GetTags(posttype, "parent-interests", postid, ApplicableInterestsTemplate, "Applicable Interests"); if (!string.IsNullOrEmpty(tagids)) { newLanguageVersionItem[fields.Key] = tagids; } break; case "Applicable Personalities": tagids = GetTags(posttype, "personality-type", postid, ApplicablePersonalitiesTemplate, "Personality Name"); if (!string.IsNullOrEmpty(tagids)) { newLanguageVersionItem[fields.Key] = tagids; } break; case "Other Applicable Evaluations": tagids = GetTags(posttype, "other-evaluations", postid, OtherApplicableEvaluationsTemplate, "Evaluation Name"); if (!string.IsNullOrEmpty(tagids)) { newLanguageVersionItem[fields.Key] = tagids; } break; //case "Reviewed by": // source = "/sitecore/content/Globals/Content Taxonomies/Article/Reviewers"; // tagids = GetTags(posttype, "child-diagnosis", newLanguageVersionItem.Fields["Reviewed by"].Source, postid, source); // if(!string.IsNullOrEmpty(tagids)){ // newLanguageVersionItem[fields.Key] = tagids; // } // break; } // newLanguageVersionItem.Fields[fields.Key].Value = fields.Value; } newLanguageVersionItem.Editing.EndEdit(); newLanguageVersionItem.Editing.AcceptChanges(); } catch (Exception ex) { newLanguageVersionItem.Editing.CancelEdit(); } } return(newLanguageVersionItem); }
public ActionResult Teams() { var items = Sitecore.Context.Database.GetItem("/sitecore/content/Home/Site Content/Teams").Children; // RenderingContext.Current.Rendering.Item.GetChildren(); var viewmodel = new TeamsModel.CountryTeams(); List <TeamsModel.CountryTeam> countryteamslist = new List <TeamsModel.CountryTeam>(); viewmodel.CountryTeamList = countryteamslist; foreach (Sitecore.Data.Items.Item child in items) { var countryteam = new TeamsModel.CountryTeam() { Country = child.Name }; List <TeamsModel.TeamInfo> teaminfolist = new List <TeamsModel.TeamInfo>(); foreach (Sitecore.Data.Items.Item team in child.Children) { Sitecore.Data.Fields.ImageField imgField = team.Fields["Team Logo"]; string imageurl = ""; if (imgField?.MediaItem != null) { imageurl = Sitecore.Resources.Media.MediaManager.GetMediaUrl(imgField.MediaItem); } TeamsModel.TeamInfo teaminfo = new TeamsModel.TeamInfo { Name = team.Fields["Name"].Value, Imgurl = imageurl }; //add members //Read the Multifield List Sitecore.Data.Fields.MultilistField multiselectField = team.Fields["Members"]; Sitecore.Data.Items.Item[] members = multiselectField.GetItems(); List <TeamsModel.Members> memberlist = new List <TeamsModel.Members>(); foreach (Item memb in members) { var member = new TeamsModel.Members(); member.Name = memb.Fields["Name"].Value; member.Email = memb.Fields["Email"].Value; Sitecore.Data.Fields.LinkField linkField = memb.Fields["LinkedIn Url"]; member.LinkedInUrl = linkField.GetFriendlyUrl(); member.TwitterHandle = memb.Fields["Twitter Handle"].Value; Sitecore.Data.Fields.LinkField website = memb.Fields["website"]; member.Website = website.GetFriendlyUrl(); memberlist.Add(member); } teaminfo.MembersList = memberlist; teaminfolist.Add(teaminfo); } countryteam.TeamsList = teaminfolist; viewmodel.CountryTeamList.Add(countryteam); } return(View(viewmodel)); }
/// <summary> /// Retrieve the friendly value of a field. /// </summary> /// <param name="me">The field.</param> /// <returns>The friendly value of the field.</returns> public static string GetFriendlyValue( this Sitecore.Data.Fields.Field me) { switch (me.Type) { case "general link": case "date": case "datetime": case "image": case "integer": case "multi-line text": case "number": case "rich text": case "single-line text": return(Sitecore.Web.UI.WebControls.FieldRenderer.Render( me.Item, me.Name)); case "file": Sitecore.Data.Fields.ImageField media = new Sitecore.Data.Fields.ImageField(me, me.Type); if (media == null || media.MediaItem == null) { return(String.Empty); } string extension = new Sitecore.Data.Items.MediaItem(media.MediaItem).Extension; string url = Sitecore.Resources.Media.MediaManager.GetMediaUrl( media.MediaItem); if (Sitecore.Configuration.Settings.ImageTypes.Contains(extension)) { return(String.Format( @"<img src=""{0}"" alt=""{1}"" />", url, media.MediaItem.Fields["alt"])); } return(String.Format( @"<a href=""{0}"">{1}</a>", Sitecore.Resources.Media.MediaManager.GetMediaUrl(media.MediaItem), media.MediaItem.Name)); case "checkbox": case "checklist": case "droplist": case "grouped droplink": case "grouped droplist": case "multilist": case "treelist": case "treelistex": case "droplink": case "droptree": case "icon": case "iframe": case "tristate": case "internal link": case "password": throw new ArgumentException("Unsupported field type"); default: throw new ArgumentException("Unknown field type: " + me.Type); } }
protected void FireRowCommand(object sender, GridViewCommandEventArgs e) { string command = e.CommandName; if (command == "FireRowCommand") { string autoId = e.CommandArgument.ToString(); if (FileUploadControl.HasFile) { try { Item mediaItem = Helper.GetDatabase().GetItem(autoId); string fileNameWithExtension = Path.GetFileName(FileUploadControl.FileName); string extention = Path.GetExtension(FileUploadControl.FileName); string filename = fileNameWithExtension.Replace(extention, ""); MemoryStream memStream = new MemoryStream(FileUploadControl.FileBytes); var options = new MediaCreatorOptions(); options.FileBased = false; options.IncludeExtensionInItemName = false; options.KeepExisting = true; options.Versioned = false; options.Destination = mediaItem.Parent.Paths.FullPath + "/" + filename; options.Database = Helper.GetDatabase(); var creator = new MediaCreator(); //Create a new item var newItem = creator.CreateFromStream(memStream, fileNameWithExtension, options); newItem.Editing.BeginEdit(); newItem.Fields["Title"].Value = filename; newItem.Fields["Alt"].Value = mediaItem.Fields["Alt"].Value; newItem.Editing.EndEdit(); Item[] referrers = Helper.GetReferrersAsItems(ref mediaItem); if (referrers != null) { Sitecore.Data.Items.MediaItem newMediaItem = new Sitecore.Data.Items.MediaItem(newItem); foreach (Item referr in referrers) { var Fields = referr.Fields.Where(x => x.Value.Contains(mediaItem.ID.ToString())); if (Fields != null && Fields.Count() > 0) { referr.Editing.BeginEdit(); foreach (var field in Fields) { if (field.Type == "Image") { Sitecore.Data.Fields.ImageField imageField = referr.Fields[field.Name]; var alt = imageField.Alt; var sclass = imageField.Class; imageField.Clear(); imageField.MediaID = newMediaItem.ID; imageField.Alt = alt; imageField.Class = sclass; } else { referr.Fields[field.Name].Value = referr.Fields[field.Name].Value.Replace(mediaItem.ID.ToString(), newItem.ID.ToString()); } } referr.Editing.EndEdit(); } } } pnSuccessUpdate.Visible = true; } catch (Exception ex) { pnFailureUpdate.Visible = true; } } else { pnFailureUpdate.Visible = true; } } }
protected void setupNormalView() { if (myDataSourceItem == null) { return; } string carID = myDataSourceItem["htmlID"]; carouselID.Text = carID; carouselID2.Text = carID; carouselID3.Text = carID; TransitionTime.Text = myDataSourceItem["transitionTime"]; PauseOnHover.Text = ""; if (myDataSourceItem["PauseOnHover"] != null && myDataSourceItem["PauseOnHover"] == "1") { PauseOnHover.Text = "hover"; } int i = 0; foreach (Item img in myDataSourceItem.Children) { if (img.TemplateName == "BootstrapImage") { string active = ""; string active2 = ""; if (i == 0) { active = " class=\"active\""; active2 = " active"; } Sitecore.Data.Fields.ImageField imgFld = (Sitecore.Data.Fields.ImageField)img.Fields["image"]; if (imgFld != null && imgFld.MediaItem != null) { Sitecore.Data.Items.MediaItem image = new Sitecore.Data.Items.MediaItem(imgFld.MediaItem); string imageURL = Sitecore.StringUtil.EnsurePrefix('/', Sitecore.Resources.Media.MediaManager.GetMediaUrl(image)); listIndicators.Text += "<li data-target=\"#" + carID + "\" data-slide-to=\"" + i + "\"" + active + "></li>"; imageObjects.Text += "<div class=\"item" + active2 + "\">"; if (!string.IsNullOrEmpty(img["link"])) { imageObjects.Text += "<a href='" + img["link"] + "'>"; } imageObjects.Text += "<img src=\"" + imageURL + "\" alt=\"" + img["title"] + "\">"; if (!string.IsNullOrEmpty(img["link"])) { imageObjects.Text += "</a>"; } imageObjects.Text += "<div class=\"carousel-caption\">"; if (!string.IsNullOrEmpty(img["title"])) { imageObjects.Text += "<h3>" + img["title"] + "<h3>"; } if (!string.IsNullOrEmpty(img["description"])) { imageObjects.Text += "<p>" + img["description"] + "</p>"; } imageObjects.Text += "</div></div>"; i++; } } } }