• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 867
  • Last Modified:

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

0
SystemSys
Asked:
SystemSys
1 Solution
 
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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now