From f427f80eaa5f941b7fddb825373e66318bd719a8 Mon Sep 17 00:00:00 2001 From: Peter Donker Date: Wed, 22 Apr 2020 22:39:57 +0200 Subject: [PATCH] Provide better feedback to end users in case something went wrong when trying to export content --- .../Website/admin/Modules/Export.ascx.cs | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/DNN Platform/Website/admin/Modules/Export.ascx.cs b/DNN Platform/Website/admin/Modules/Export.ascx.cs index ff500c6d687..d17c85cdd48 100644 --- a/DNN Platform/Website/admin/Modules/Export.ascx.cs +++ b/DNN Platform/Website/admin/Modules/Export.ascx.cs @@ -82,8 +82,8 @@ private string ExportModule(int moduleID, string fileName, IFolderInfo folder) { var objObject = Reflection.CreateObject(Module.DesktopModule.BusinessControllerClass, Module.DesktopModule.BusinessControllerClass); - //Double-check - if (objObject is IPortable) + //Double-check + if (objObject is IPortable) { XmlDocument moduleXml = new XmlDocument { XmlResolver = null }; XmlNode moduleNode = ModuleController.SerializeModule(moduleXml, Module, true); @@ -104,9 +104,9 @@ private string ExportModule(int moduleID, string fileName, IFolderInfo folder) var content = sw.ToString(); if (!String.IsNullOrEmpty(content)) { - //remove invalid chars in content -> DNN 26810: Handled by ModuleController.SerializeModule - //content = Regex.Replace(content, _invalidCharsRegex, string.Empty); - //add attributes to XML document + //remove invalid chars in content -> DNN 26810: Handled by ModuleController.SerializeModule + //content = Regex.Replace(content, _invalidCharsRegex, string.Empty); + //add attributes to XML document //content = "" + "" + content + ""; @@ -114,10 +114,10 @@ private string ExportModule(int moduleID, string fileName, IFolderInfo folder) if (PortalController.Instance.HasSpaceAvailable(PortalId, content.Length)) { //add file to Files table - using (var fileContent = new MemoryStream(Encoding.UTF8.GetBytes(content))) - { + using (var fileContent = new MemoryStream(Encoding.UTF8.GetBytes(content))) + { Services.FileSystem.FileManager.Instance.AddFile(folder, fileName, fileContent, true, true, "application/octet-stream"); - } + } } else { @@ -134,9 +134,16 @@ private string ExportModule(int moduleID, string fileName, IFolderInfo folder) strMessage = Localization.GetString("ExportNotSupported", LocalResourceFile); } } - catch + catch (Exception ex) { - strMessage = Localization.GetString("Error", LocalResourceFile); + if (ex is InvalidFileExtensionException || ex is PermissionsNotMetException || ex is InvalidFilenameException) + { + strMessage = ex.Message; + } + else + { + strMessage = Localization.GetString("Error", LocalResourceFile); + } } } else @@ -227,7 +234,7 @@ protected void OnExportClick(object sender, EventArgs e) { UI.Skins.Skin.AddModuleMessage(this, strMessage, ModuleMessage.ModuleMessageType.RedError); } - } + } } else