From 8d1b6aeab001cdea474b431647d7bc6a9188e2b6 Mon Sep 17 00:00:00 2001 From: Mikhail Tymchuk Date: Thu, 31 Mar 2016 12:35:24 +0300 Subject: [PATCH] move path resolution to AjaxFileUpload --- AjaxControlToolkit.Jasmine/Global.asax.cs | 2 +- AjaxControlToolkit.SampleSite/Global.asax | 2 +- .../AjaxFileUpload/AjaxFileUpload.cs | 16 +++++++++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/AjaxControlToolkit.Jasmine/Global.asax.cs b/AjaxControlToolkit.Jasmine/Global.asax.cs index 704fc0e46..36fad6979 100644 --- a/AjaxControlToolkit.Jasmine/Global.asax.cs +++ b/AjaxControlToolkit.Jasmine/Global.asax.cs @@ -11,7 +11,7 @@ protected void Application_Start(object sender, EventArgs e) { RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); - AjaxFileUploadHelper.RootTempFolderPath = HttpContext.Current.Server.MapPath("~/Temp"); + AjaxFileUploadHelper.RootTempFolderPath = "~/Temp"; AjaxControlToolkit.ToolkitResourceManager.RegisterControl(typeof(Suites.ToolkitResourceManager.TestExtender)); } diff --git a/AjaxControlToolkit.SampleSite/Global.asax b/AjaxControlToolkit.SampleSite/Global.asax index 0585122a3..c27acbecb 100644 --- a/AjaxControlToolkit.SampleSite/Global.asax +++ b/AjaxControlToolkit.SampleSite/Global.asax @@ -12,7 +12,7 @@ "~/Scripts/WebForms/MsAjax/MicrosoftAjaxWebForms.js")); // In Medium Trust environments, set AjaxFileUploadHelper.RootTempFolderPath to an existing directory located within the web application root. - AjaxFileUploadHelper.RootTempFolderPath = HttpContext.Current.Server.MapPath("~/Temp"); + AjaxFileUploadHelper.RootTempFolderPath = "~/Temp"; BundleTable.EnableOptimizations = true; } diff --git a/AjaxControlToolkit/AjaxFileUpload/AjaxFileUpload.cs b/AjaxControlToolkit/AjaxFileUpload/AjaxFileUpload.cs index 932357770..4f53215e8 100644 --- a/AjaxControlToolkit/AjaxFileUpload/AjaxFileUpload.cs +++ b/AjaxControlToolkit/AjaxFileUpload/AjaxFileUpload.cs @@ -392,9 +392,12 @@ public static string BuildRootTempFolder() { var userPath = AjaxFileUploadHelper.RootTempFolderPath; if(userPath != null) { - if(!Directory.Exists(userPath)) - throw new IOException(String.Format("Temp directory '{0}' does not exist.")); - return userPath; + var physicalPath = GetPhysicalPath(userPath); + + if(!Directory.Exists(physicalPath)) + throw new IOException(String.Format("Temp directory '{0}' does not exist.", physicalPath)); + + return physicalPath; } var defaultPath = Path.Combine(Path.GetTempPath(), DefaultTempSubDir); @@ -405,6 +408,13 @@ public static string BuildRootTempFolder() { return defaultPath; } + static string GetPhysicalPath(string path) { + if(path.StartsWith("~")) + return HttpContext.Current.Server.MapPath(path); + + return path; + } + internal void CreateChilds() { Controls.Clear(); CreateChildControls();