GetMedia() public static method

public static GetMedia ( int mediaId ) : umbraco.cms.businesslogic.media.Media
mediaId int
return umbraco.cms.businesslogic.media.Media
示例#1
0
        public static string GetImageTag(string imagePathOrMediaId, int maxWidth, int maxHeight, bool constrain)
        {
            if (string.IsNullOrEmpty(imagePathOrMediaId))
            {
                return(string.Empty);
            }

            int mediaId = CommonUtil.ConvertToIntSafe(imagePathOrMediaId, -1);

            if (mediaId == -1)
            {
                return(GetImageTag(imagePathOrMediaId, maxWidth, maxHeight));
            }

            Media media = UmbracoUtil.GetMedia(mediaId);

            if (media != null)
            {
                string file = media.GetPropertyValue("umbracoFile", string.Empty);
                if (!string.IsNullOrEmpty(file))
                {
                    string alt = HttpUtility.HtmlEncode(media.Text);

                    string thumbnailUrl = ImageUtil.ThumbnailUrl(file, maxWidth, maxHeight, constrain);
                    return(GetImageTag(thumbnailUrl, alt));
                }
            }
            return(string.Empty);
        }
示例#2
0
        /// <summary>
        /// Gets the media path via a media id
        /// </summary>
        /// <param name="mediaId">The media id.</param>
        /// <returns>The file path to the media</returns>
        /// <example>
        /// <code lang="xsl" title="">
        /// <![CDATA[
        /// <xsl:value-of select="upac:GetMediaPath(1101)" />
        /// Would give: /media/1101/image.jpg
        /// ]]>
        /// </code>
        /// </example>
        public static string GetMediaPath(int mediaId)
        {
            Media media = UmbracoUtil.GetMedia(mediaId);

            if (media != null)
            {
                return(media.GetPropertyValue("umbracoFile", string.Empty));
            }
            return(string.Empty);
        }
示例#3
0
 public static string ThumbnailUrl(int mediaId, int width, int height, bool constrain)
 {
     Media media = UmbracoUtil.GetMedia(mediaId);
     if (media != null)
     {
         string imagePath = media.GetPropertyValue("umbracoFile", string.Empty);
         return ThumbnailUrl(imagePath, width, height, constrain);
     }
     return string.Empty;
 }