I am using VB to upload image files to my server but am having problems. How can I use the ContentType to filter only image files? This is my code for my upload button which does not seem to be working. I can only upload bmp files:
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
If txtFileUpload.PostedFile.ContentLength = 0 Then
lblMessage.Text = "No file to upload"
'if the upload does not contain an image...error
If txtSaveAs.Text Is Nothing OrElse txtSaveAs.Text.Trim() = "" Then
txtSaveAs.Text = txtFileUpload.FileName
txtSaveAs.Text = txtSaveAs.Text.Trim()
Dim path As String = Server.MapPath("~/images")
Dim fileType As String = txtFileUpload.PostedFile.ContentType
If fileType = "image/bmp" Or fileType = "image/jpg" Then
txtFileUpload.PostedFile.SaveAs(path & "\" & txtSaveAs.Text)
lblMessage.Text = "file sucessfully uploaded to: "
lblPath.Text = path & "/" & txtSaveAs.Text
View Complete Post