Media Properties

Media Properties

Media Items

  • An item which contains a binary media resource and sometimesinformation about the file on disk which contains the media
  • Storing media in the file system instead of the database increases publishing overhead
    • Mediastored in the database can be easily published to a publishing target
    • Media stored in the file systemrequires synchronization of directories and files between servers

Sitecore Media Items Guidelines

  • Use the database to store media rather than the file system
  • Organize the folder structure of the media library so that it is easy to navigate for non-technical users
  • Assign names that can be easily recognized and understood by business users
  • Use a graphics program to optimize media items to increase performance

Media Properties C# Web Control Code

Sitecore.Data.Items.Item item = this.GetItem();
if (item == null) return;

string mediaItemPath = "/sitecore/media library/Images/TIC/Awards/Color/PeggyMooneyRec";
Sitecore.Data.Items.Item imageItem = Sitecore.Context.Database.GetItem(mediaItemPath);
if (item == null) return;
Sitecore.Data.Items.MediaItem mediaItem = new Sitecore.Data.Items.MediaItem(imageItem);

string mediaUrl = Sitecore.Resources.Media.MediaManager.GetMediaUrl(mediaItem);
char mediaPrefix = '/';
string imageUrl = Sitecore.StringUtil.EnsurePrefix(mediaPrefix, mediaUrl);
if (string.IsNullOrEmpty(imageUrl)) return;

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold; width:100%; clear:both");
output.Write("C# Web Control Real-time Output");
output.RenderEndTag(); //Div

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-size:x-small; width:100%; clear:both");
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold");
string displayName = Sitecore.StringUtil.GetString(item.DisplayName, item.Name);
//using : for colon and ? for question mark and   for space
output.Write("{0}: {1}", "Item", displayName);
output.RenderEndTag(); //P

output.Write("{0}&#58;&#160;{1}", "Display Name", "<b>" + mediaItem.DisplayName + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Alternate Text", "<b>" + mediaItem.Alt + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Description", "<b>" + mediaItem.Description + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Extension", "<b>" + mediaItem.Extension + "</b><br/>");
output.Write("{0}&#63;&#160;{1}", "File Based", "<b>" + mediaItem.FileBased.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "File Path", "<b>" + mediaItem.FilePath + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Icon", "<b>" + mediaItem.Icon + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "ID", "<b>" + mediaItem.ID.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Media Path", "<b>" + mediaItem.MediaPath + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Mime Type", "<b>" + mediaItem.MimeType + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Name", "<b>" + mediaItem.Name + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Path", "<b>" + mediaItem.Path + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Size", "<b>" + mediaItem.Size.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Title", "<b>" + mediaItem.Title + "</b>");
output.RenderEndTag(); //Div