From 34f9d84e5efdbcd817dc233e016713006f8d3914 Mon Sep 17 00:00:00 2001 From: hartvig Date: Fri, 20 Aug 2010 09:09:19 +0000 Subject: [PATCH] Fixes 28407 [TFS Changeset #75946] --- .../mediapicker/mediaChooser.cs | 3 +- .../controls/Images/ImageViewer.ascx.cs | 59 ++++++++++--------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/components/editorControls/mediapicker/mediaChooser.cs b/components/editorControls/mediapicker/mediaChooser.cs index 5939450ea4..5de0c24658 100644 --- a/components/editorControls/mediapicker/mediaChooser.cs +++ b/components/editorControls/mediapicker/mediaChooser.cs @@ -14,6 +14,7 @@ using System.Web.UI.HtmlControls; using System.Resources; using umbraco.editorControls.mediapicker; using umbraco.uicontrols.TreePicker; +using umbraco.cms.businesslogic; namespace umbraco.editorControls { /// @@ -148,7 +149,7 @@ namespace umbraco.editorControls if (_showpreview) { - if (string.IsNullOrEmpty(ItemIdValue.Value)) + if (string.IsNullOrEmpty(ItemIdValue.Value) || !CMSNode.IsNode(int.Parse(ItemIdValue.Value))) { PreviewContainer.Style.Add(HtmlTextWriterStyle.Display, "none"); ImgViewer.MediaId = -1; diff --git a/umbraco/presentation/umbraco/controls/Images/ImageViewer.ascx.cs b/umbraco/presentation/umbraco/controls/Images/ImageViewer.ascx.cs index e52522bae7..2a6ae40b42 100644 --- a/umbraco/presentation/umbraco/controls/Images/ImageViewer.ascx.cs +++ b/umbraco/presentation/umbraco/controls/Images/ImageViewer.ascx.cs @@ -5,6 +5,7 @@ using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using umbraco.cms.businesslogic.media; +using umbraco.cms.businesslogic; namespace umbraco.controls.Images { @@ -77,40 +78,44 @@ namespace umbraco.controls.Images } private void LookupData() - { - if (MediaId > 0) - { - Media m = new Media(MediaId); + { + if (MediaId > 0 && Media.IsNode(MediaId)) + { + Media m = new Media(MediaId); - // TODO: Remove "Magic strings" from code. - var pFile = m.getProperty("fileName"); - if (pFile == null) pFile = m.getProperty("umbracoFile"); - if (pFile == null) pFile = m.getProperty("file"); - if (pFile == null) - { - //the media requested does not correspond with the standard umbraco properties - return; - } + // TODO: Remove "Magic strings" from code. + var pFile = m.getProperty("fileName"); + if (pFile == null) pFile = m.getProperty("umbracoFile"); + if (pFile == null) pFile = m.getProperty("file"); + if (pFile == null) + { + //the media requested does not correspond with the standard umbraco properties + return; + } - MediaItemPath = pFile.Value != null && !string.IsNullOrEmpty(pFile.Value.ToString()) - ? umbraco.IO.IOHelper.ResolveUrl(pFile.Value.ToString()) + MediaItemPath = pFile.Value != null && !string.IsNullOrEmpty(pFile.Value.ToString()) + ? umbraco.IO.IOHelper.ResolveUrl(pFile.Value.ToString()) : "#"; - AltText = MediaItemPath != "#" ? m.Text : ui.GetText("no") + " " + ui.GetText("media"); + AltText = MediaItemPath != "#" ? m.Text : ui.GetText("no") + " " + ui.GetText("media"); - var pWidth = m.getProperty("umbracoWidth"); - var pHeight = m.getProperty("umbracoHeight"); + var pWidth = m.getProperty("umbracoWidth"); + var pHeight = m.getProperty("umbracoHeight"); - if (pWidth != null && pWidth.Value != null && pHeight != null && pHeight.Value != null) - { - int.TryParse(pWidth.Value.ToString(), out m_FileWidth); - int.TryParse(pHeight.Value.ToString(), out m_FileHeight); - } + if (pWidth != null && pWidth.Value != null && pHeight != null && pHeight.Value != null) + { + int.TryParse(pWidth.Value.ToString(), out m_FileWidth); + int.TryParse(pHeight.Value.ToString(), out m_FileHeight); + } - string ext = MediaItemPath.Substring(MediaItemPath.LastIndexOf(".") + 1, MediaItemPath.Length - MediaItemPath.LastIndexOf(".") - 1); - MediaItemThumbnailPath = MediaItemPath.Replace("." + ext, "_thumb.jpg"); + string ext = MediaItemPath.Substring(MediaItemPath.LastIndexOf(".") + 1, MediaItemPath.Length - MediaItemPath.LastIndexOf(".") - 1); + MediaItemThumbnailPath = MediaItemPath.Replace("." + ext, "_thumb.jpg"); - ImageFound = true; - } + ImageFound = true; + } + else + { + ImageFound = false; + } } } } \ No newline at end of file