Return to doc.sitecore.com

Valid for Sitecore 5.3.1
5.  File
Prev Next

A field of type file holds a link to a file in the media library. It can be accessed by using one of the following methods.

The format of the File field in Sitecore v5.3.1 is the following.

<file mediaid="<media_item_id>" src="<media_item_path>" />

For example;

<file mediaid="{9C19B3D2-D32E-4DA7-9815-2EBA66C9FFC7}" src="~/media/9C19B3D2D32E4DA798152EBA66C9FFC7.ashx" />

To access the field values you need to do the following:

In c# code:
with the Sitecore.Data.Fields.ImageField class:

ImageField field = Sitecore.Context.Item.Fields[fieldName];
if (field != null)
  {
  string src = field.Src;
  string mediaID = field.MediaID.ToString();
}

with the Sitecore.Data.Fields.XmlField class:

XmlField xmlField = Sitecore.Context.Item.Fields[fieldName];
if (xmlField != null)
  {
  string src = xmlField.GetAttribute("src");
  string mediaID = xmlField.GetAttribute("mediaid");
}

In an xslt rendering:

<xsl:value-of select="sc:fld('File',.,'src')"/><br/>

<xsl:value-of select="sc:fld('File',.,'mediaid')"/>


Prev Next