Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim UploadPath As String = ConfigurationSettings.AppSettings.Get("UploadPath")
'-- This is the loading image
ImgLoading.Visible = False
'-- The upload button generates a postback
If IsPostBack Then
'-- Show the loading image
ImgLoading.Visible = True
Dim path As String = Server.MapPath("~/" + UploadPath + "/")
Dim fileOK As Boolean = False
If FileUpload1.HasFile Then
Dim fileExtension As String
fileExtension = System.IO.Path. _
GetExtension(FileUpload1.FileName).ToLower()
Dim allowedExtensions As String() = _
{".jpg", ".jpeg", ".xls", ".pps", ".doc"}
For i As Integer = 0 To allowedExtensions.Length - 1
If fileExtension = allowedExtensions(i) Then
fileOK = True
End If
Next
If fileOK Then
Try
FileUpload1.PostedFile.SaveAs(path & _
FileUpload1.FileName+ fileExtension)
Label1.Text = "File uploaded"
Catch ex As Exception
Label1.Text = "File can't be uploaded"
End Try
Else
Label1.Text = "File extention is not allowed"
End If
End If
'-- and hide the loading image again
ImgLoading.Visible = False
End If
End Sub