Home All Groups Group Topic Archive Search About

How to filter file types when using the HTMLInputFile control...

Author
20 Dec 2005 9:33 AM
Asela Gunawardena
On my Web Servers, I don't want to allow visitors to upload executables.
There are many types of files that i want to ignore (for instance: exe,dll,
bat, cmd .etc). I have an ASPX page with an HTMLInputFile control which
uploads the files. Is it possible to set a filter when the user clicks the
Browse button so that the
file selection dialog only displays valid formats specified.

thankx in advance

Asela Gunawardena.

Author
21 Dec 2005 5:14 AM
dbottjer
You could maintain a list of acceptable file types in a collection and then
loop through this collection checking it against the file being uploaded. 
You would need to use some VB.NET code like this:

fileExtension = Mid(fileName, InStrRev(fileName, ".") + 1)

To figure out the file extension of the uploaded file.

Show quoteHide quote
"Asela Gunawardena" wrote:

> On my Web Servers, I don't want to allow visitors to upload executables.
> There are many types of files that i want to ignore (for instance: exe,dll,
> bat, cmd .etc). I have an ASPX page with an HTMLInputFile control which
> uploads the files. Is it possible to set a filter when the user clicks the
> Browse button so that the
> file selection dialog only displays valid formats specified.
>
> thankx in advance
>
> Asela Gunawardena.
>
>
>
Author
21 Dec 2005 6:33 AM
Asela Gunawardena
thankx, but this of course i do check. what i would like to know is whether
there is a way of restricting the user select the unnessary formats when the
file dialog appears; making only the relavant types appear.


Show quoteHide quote
"dbottjer" <dbott***@discussions.microsoft.com> wrote in message
news:B03045D1-F7E0-440F-B744-27B896C40539@microsoft.com...
> You could maintain a list of acceptable file types in a collection and
> then
> loop through this collection checking it against the file being uploaded.
> You would need to use some VB.NET code like this:
>
> fileExtension = Mid(fileName, InStrRev(fileName, ".") + 1)
>
> To figure out the file extension of the uploaded file.
>
> "Asela Gunawardena" wrote:
>
>> On my Web Servers, I don't want to allow visitors to upload executables.
>> There are many types of files that i want to ignore (for instance:
>> exe,dll,
>> bat, cmd .etc). I have an ASPX page with an HTMLInputFile control which
>> uploads the files. Is it possible to set a filter when the user clicks
>> the
>> Browse button so that the
>> file selection dialog only displays valid formats specified.
>>
>> thankx in advance
>>
>> Asela Gunawardena.
>>
>>
>>