Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

i am trying to upload files of a certain type, say image. but using the HTMLInputFile control, i cannot seem to restrict the file types. can anyone help me on this?

 

i tried the property FileBrowser.Accept = "image/*";

 

on Page_Load(). this does not work.

 

"FileBrowser" is the name of my HTMLInputFile control.

  • Moderators
Posted

The following allows pdf, txt and zip (for example)

Dim UpFile As HttpPostedFile = FileBrowser.PostedFile
If ValidateUploadFileType(UpFile.ContentType.ToString) Then
   'valid
else
   'not valid
end if  

 Private Function ValidateUploadFileType(ByVal txt As String) As Boolean
       If txt.IndexOf("text/plain") > -1 OrElse txt.IndexOf("x-zip") > -1 OrElse txt.IndexOf("pdf") > -1 Then
           Return True
       Else
           Return False
       End If
   End Function

Visit...Bassic Software
Posted

using wildcard

 

Thank you for the reply. But what i want to do is, give a wildcard character or something so that i dont have to specify the extension name each time in the IF condition. Say, i want all IMAGE types - it would be nice if i could just mention "*" or something so that the FILE DIALOG box which pops up shows only those image file options in the "FileTypes".

 

Get what i mean?

  • Moderators
Posted

Sorry I misunderstood your question.

 

I would put a bunch of OrElse together and list the types (jpg,gif, bmp, etc)

For example, I wouldn't allow PCX format. (but that's just me)

Visit...Bassic Software
Posted

Thank you, people. I also read somewhere that the ACCEPT property of the HTMLFileInput class works only for Netscape and not for IE.

 

If anyone gets any further info on the same / if it is possible in any way, please revert. Thanks.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...