Upload allow only image files in the formats .jpg, .gif and .png

greetings to you
sir, experts

how i can upload only image files only
files in the formats .jpg, .gif and .png using FILE_UPLOAD CONTROL
PLEASE GIVE ME CLEAR Example because i'm tire from searching in web

please reply as soon as possible

my best regards

SystemSysAsked:
Who is Participating?
 
JRockFLCommented:
Here is a piece of sample code from a previous project. Pretty much you want to evaluate the file extension.
    Protected Sub cmd_upload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmd_upload.Click
 
        Try
 
            If Me.img.PostedFile.FileName = "" Then
 
                Me.pnl_error.Visible = True
                Me.lbl_error.Text = "No photo was attached."
                Exit Sub
 
            Else
 
                Select Case Right(Me.img.PostedFile.FileName, 3).ToLower()
 
                    Case "jpg", "gif", "png"
                    'add code to save file
 
                    Case Else
 
                        Me.pnl_error.Visible = True
                        Me.lbl_error.Text = "The file format you attached is not supported."
                        Exit Sub
 
                End Select
 
            End If
 
        Catch ex As Exception
 
            Me.pnl_error.Visible = True
            Me.lbl_error.Text = ex.Message
 
        End Try
 
    End Sub

Open in new window

0
 
sm394Commented:
string ext=System.IO.Path.GetExtension(FileUpload1.PostedFile.FileName);
        if (ext.Equals(".jpg") ||ext.Equals(".gif")||ext.Equals(".png"))
{
//do smth
}else
        {
            return;
        }
0
 
jabcocoCommented:
This is what i suggest.
List<string> oAvailExtensions = new List<string>(){".jpg",".gif",".png"};
if (FileUpload1.HasFile){
    string sEx = Path.GetExtension(FileUpload1.PostedFile.FileName);
    if (oAvailExtensions.Contains(sEx))
    {}
}

Open in new window

0
 
SystemSysAuthor Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.