Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
Is is possible to raise a custom validator when uploading a media?
I have this image resizer datatype that I got from daniel. I'm customizing it to raise an error when the image size exceeds 120kb. How can I do that?
Here's my code
internal bool validateFileSizePath(string origFile){ try{ HttpServerUtility map = HttpContext.Current.Server; string path = map.MapPath(origFile);System.IO. FileInfo info = new System.IO.FileInfo(path); if (info.Length <= 120000){ return true;} else{_customValidator.ControlToValidate = _imageResizerImage.ImageUrl;_customValidator.Validate();_customValidator.ErrorMessage = "Invalid image size. Maximum image size should be 120kb"; return false;}} catch (Exception ex){_customValidator.ControlToValidate = _imageResizerImage.ImageUrl;_customValidator.Validate();_customValidator.ErrorMessage = "Invalid image size. Maximum image size should be 120kb. " + ex; return false;} }
internal bool validateFileSizePath(string origFile)
{
try
HttpServerUtility map = HttpContext.Current.Server;
string path = map.MapPath(origFile);
System.IO.
FileInfo info = new System.IO.FileInfo(path);
if (info.Length <= 120000)
return true;
}
else
_customValidator.ControlToValidate = _imageResizerImage.ImageUrl;
_customValidator.Validate();
_customValidator.ErrorMessage =
"Invalid image size. Maximum image size should be 120kb";
return false;
catch (Exception ex)
"Invalid image size. Maximum image size should be 120kb. " + ex;
and then I call it in
private void DataEditorControl_OnSave(EventArgs e){ var prevalueEditor = (ImageResizerPrevalueEditor)PrevalueEditor; if (_imageResizerDataEditor.validateFileSizePath(ImageResizerHelper.GetOriginalUrl(ImageResizerHelper.CurrentNodeId, prevalueEditor))){ var imageUrl = ImageResizerHelper.ResizeImage(ImageResizerHelper.GetOriginalUrl(ImageResizerHelper.CurrentNodeId, prevalueEditor), prevalueEditor.MaxHeight, prevalueEditor.MaxHeight);_imageResizerDataEditor.ImageUrl = imageUrl; base.Data.Value = _imageResizerDataEditor.ImageUrl;}}
private
void DataEditorControl_OnSave(EventArgs e)
var prevalueEditor = (ImageResizerPrevalueEditor)PrevalueEditor;
if (_imageResizerDataEditor.validateFileSizePath(ImageResizerHelper.GetOriginalUrl(ImageResizerHelper.CurrentNodeId, prevalueEditor)))
var imageUrl = ImageResizerHelper.ResizeImage(ImageResizerHelper.GetOriginalUrl(ImageResizerHelper.CurrentNodeId, prevalueEditor), prevalueEditor.MaxHeight, prevalueEditor.MaxHeight);
_imageResizerDataEditor.ImageUrl = imageUrl;
base.Data.Value = _imageResizerDataEditor.ImageUrl;
Am I getting this right?
Hi Sherry,
I think the problem may be that the custom validator needs to be assigned to the same group as the other page validation controls.
Are you getting an error, or is the validator just not firing?
Sometimes it is generating an error and it is not firing.
I tried to create a BeforeSaveEventHandler class but i'm not sure where to call it in the dataeditor class.
How do you add the custom validator to the page validation controls?
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
How to raise a custom validator when saving a media
Hi,
Is is possible to raise a custom validator when uploading a media?
I have this image resizer datatype that I got from daniel. I'm customizing it to raise an error when the image size exceeds 120kb. How can I do that?
Here's my code
Hi Sherry,
I think the problem may be that the custom validator needs to be assigned to the same group as the other page validation controls.
Are you getting an error, or is the validator just not firing?
Sometimes it is generating an error and it is not firing.
I tried to create a BeforeSaveEventHandler class but i'm not sure where to call it in the dataeditor class.
How do you add the custom validator to the page validation controls?
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.