diff --git a/source/nuPickers/Helper.cs b/source/nuPickers/Helper.cs index 76a08bd..3918c50 100644 --- a/source/nuPickers/Helper.cs +++ b/source/nuPickers/Helper.cs @@ -9,6 +9,7 @@ using System.Web; using System.Web.Hosting; using Umbraco.Web; + using Umbraco.Core.Logging; internal static class Helper { @@ -104,34 +105,44 @@ internal static string GetDataFromUrl(string url) { string data = string.Empty; - if (!string.IsNullOrEmpty(url)) + try { - if (VirtualPathUtility.IsAppRelative(url)) // starts with ~/ - { - bool fileExists = false; - if (!url.Contains("?")) + if (!string.IsNullOrEmpty(url)) + { + if (VirtualPathUtility.IsAppRelative(url)) // starts with ~/ { - string filePath = HttpContext.Current.Server.MapPath(url); + bool fileExists = false; + + if (!url.Contains("?")) + { + string filePath = HttpContext.Current.Server.MapPath(url); + + if (File.Exists(filePath)) + { + url = filePath; + fileExists = true; + } + } - if (File.Exists(filePath)) + if (!fileExists) { - url = filePath; - fileExists = true; + url = url.Replace("~/", + (HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/")); } } - if (!fileExists) + using (WebClient client = new WebClient()) { - url = url.Replace("~/", (HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/")); - } - } + data = client.DownloadString(url); - using (WebClient client = new WebClient()) - { - data = client.DownloadString(url); + } } } + catch (Exception e) + { + LogHelper.Warn("Error getting data from Url (url: " + url + " ): " + e.Message + " :: " + e.StackTrace); + } return data; } diff --git a/source/nuPickers/Shared/JsonDataSource/JsonDataSource.cs b/source/nuPickers/Shared/JsonDataSource/JsonDataSource.cs index da56b11..70ca4a0 100644 --- a/source/nuPickers/Shared/JsonDataSource/JsonDataSource.cs +++ b/source/nuPickers/Shared/JsonDataSource/JsonDataSource.cs @@ -54,6 +54,7 @@ private IEnumerable GetEditorDataItems(int contextId) try { + this.Url = this.Url.Replace("@contextId", contextId.ToString()); jToken = JToken.Parse(Helper.GetDataFromUrl(this.Url)); } catch (JsonException jsonException)