ASPxClientUploadControlValidationSettings.invalidFileNameCharacters Property

Gets which characters in a file name are not allowed.

Declaration

invalidFileNameCharacters: string[]

Property Value

Type Description
string[]

An array of string values that contains characters that are not allowed.

Example

The following example illustrates how to use the ASPxClientUploadControl.ValidationErrorOccurred event to customize an error message for files that didn’t pass validation.

    function onUploadControlValidationErrorOccured(s, e) {
        e.showAlert = false;
        var errorHtmlContentTemplate = "<div class=\"error-attention\">Attention!</div><br />" +
            "{0} files are invalid and will not be uploaded.<br /><br /> {1}" +
            "All files listed above have been removed from the selection.";

        var preparedErrorHtmlContent = errorHtmlContentTemplate
            .replace("{0}", e.invalidFiles.length)
            .replace("{1}", getDetailsErrorInfoHtml(e));

        popupControl.SetContentHtml(preparedErrorHtmlContent);
        popupControl.Show();
    }
    function getDetailsErrorInfoHtml(e) {
        var html = "";
        html += getDetailsErrorInfoHtmlByErrorType(e, ASPxClientUploadControlValidationErrorTypeConsts.MaxFileCountExceeded,
            "These files exceed the allowed file count (the maximum file count is {0}):<br /><ul>{1}</ul><br />",
            e.validationSettings.maxFileCount);
        html += getDetailsErrorInfoHtmlByErrorType(e, ASPxClientUploadControlValidationErrorTypeConsts.MaxFileSizeExceeded,
            "These files exceed the allowed file size (the maximum file size is {0} bytes):<br /><ul>{1}</ul><br />",
            e.validationSettings.maxFileSize, true);
        html += getDetailsErrorInfoHtmlByErrorType(e, ASPxClientUploadControlValidationErrorTypeConsts.NotAllowedFileExtension,
            "Extensions of these files are not allowed (valid extensions are - {0}):<br /><ul>{1}</ul><br />",
            e.validationSettings.allowedFileExtensions.join(', '));
        html += getDetailsErrorInfoHtmlByErrorType(e, ASPxClientUploadControlValidationErrorTypeConsts.FileNameContainInvalidCharacter,
            "Names of this files contain invalid characters ({0}):<br /><ul>{1}</ul><br />",
            e.validationSettings.invalidFileNameCharacters.join(","));
        return html;
    }
    function getDetailsErrorInfoHtmlByErrorType(e, errorType, message, commonInfo, isFileSize) {
        var filesInfo = getFilesInfoByErrorType(e.invalidFiles, errorType);
        if (filesInfo.length == 0)
            return "";
        var filesHtml = "";
        for (var i = 0, len = filesInfo.length; i < len; i++) {
            var f = filesInfo[i];
            var fileText = isFileSize ? f.fileName + " - " + f.fileSize + " bytes" : f.fileName;
            filesHtml += "<li class=\"error-file\">" + fileText + "</li>";
        }
        return "<div class=\"error-detail\">" + message.replace("{0}", commonInfo).replace("{1}", filesHtml) + "</div>";
    }
    function getFilesInfoByErrorType(invalidFiles, errorType) {
        var filesInfo = [];
        for (var i = 0, len = invalidFiles.length; i < len; i++) {
            var fileInfo = invalidFiles[i];
            if (fileInfo.errorType == errorType)
                filesInfo.push(fileInfo);
        }
        return filesInfo;
    }
See Also