RadControls
version |
Q1 2010
|
.NET version |
3.5
|
Visual Studio
version |
2010
|
programming
language |
VB.NET
|
browser support |
all browsers supported by
RadControls
|
TITLE
Retrieving the name of the uploaded file(s)
and directory for restricting file upload/rename or directory
creation/rename checking the name by Regular Expression
PROJECT DESCRIPTION
There is not a built
in function in Rad File Explorer (that is the component inside Rad
Editor dialogs) to inhibit uploading/renaming file name or
creating/renaming directory with strange chars like "$" or "%" and so
on. It happens that in a CMS solution built with RadControls the user
loads file with these chars and even if windows server accepts them the
file system could be "dirty" and full of strange file. The same thing
happens with the creation of directory or renaming of files.
In
this solution I created a new class derived
from Telerik.Web.UI.Widgets.FileSystemContentProvider that though a
simple regular expression check what the user loads or renames and in
case the names are not compatible with the rules of the website answer
change automatically changes the name and upload or advises the user with
an alert and of course cancel the operation itself.
I
commented all the code and I created a region called "customization"
where the developer can change the behavior of the message of the class.
In depth:
_strRegex >>>>
The regular expression that corresponds to the website rules
_strChaneForInvalidChar
>>>> The char that substitutes the invalid chars
find by the regex
_blnConsiderOverWriteFilesChangingName
>>>> Works only on the upload file, represents if the
developer wants to check about an existing file
_TypeAdvise
= Enum, the developer can check if he want to advise the user
with an alert or change the name directly
_strAlertForRenameFile
= Message for the alert about rename file
_strAlertForUploadFile =
Message for the alert about upload file
_strAlertForAlreadyExistingFile
= Message for the alert about already existing file, it happens
when the file uploaded is not the same into the directory (the
component block it) but with changing by the code could be in the dir.
_strAlertForRenameDir
= Message for the alert about rename directory
_strAlertForCreateDir =
Message for the alert about create directory
There
is also a function called "ReturnCorrectString" that the developer have
to change for implementing its own changing logic for require the website's
rule.