Quantcast
Channel: DevNet Questions
Viewing all articles
Browse latest Browse all 8832

Kentico 10 - Override File Upload Error Message

$
0
0
I have the following case and I really appreciate your kind support to resolve it:I’ve created a new page type (let’s call it MyNewsPageType) which has been inherited from original News page type.On that page type, I’ve Teaser field on which I will use it to upload an image.I created a custom CMSLoaderAttribute and registered the following event:AttachmentInfo.TYPEINFO.Events.Insert.Before += Insert_Before;I did that because I have a custom logic I want to execute before uploading/persisting file to Kentico DB.In case one of my business rule was not met, I need to terminate the upload process and display a custom error message to the user based on the error/exception occurred.What I did so far, to terminate the upload process, I throw a general Exception and I pass my custom message. However, although the file not being uploaded, the error messagebeing displayed to the user is always the same (check attached image). Which means that my custom error message is being overridden somewhere in the file upload handler (CMSModules/Content/CMSPages/MultiFileUploader.ashx). The message that being returned is: “An error occurred during the file upload.”Please let me know how I can replace that message with a custom error.Code of CMSLoaderAttribute :[FileUploadEventsAttribute] public partial class CMSModuleLoader { /// @summary@ /// Attribute class that ensures the loading of custom handlers. /// @/summary@ private class FileUploadEventsAttribute : CMSLoaderAttribute { /// @summary@ /// The system executes the Init method of the CMSModuleLoader attributes when the application starts. /// @/summary@ public override void Init() { AttachmentInfo.TYPEINFO.Events.Insert.Before += Insert_Before; } private void Insert_After(object sender, ObjectEventArgs e) { AttachmentInfo current = (AttachmentInfo)e.Object; } private delegate void DoStuff(); private void Insert_Before(object sender, ObjectEventArgs e) { var myValidationLogic = false; // I fixed the value just for demonstration poupose. if (!myValidationLogic) { var customErrorMessage = @this is the message that should be displayed to the user@; throw new Exception(customErrorMessage); } } }

Viewing all articles
Browse latest Browse all 8832

Trending Articles