Hello Dear
Try this code it will solve ur problem,
code:
Protected Sub AddFile_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddFile.Click
Dim ext As String = System.IO.Path.GetExtension(FindFile.PostedFile.FileName)
If Not FindFile.Value = "" Then
If ext = ".gif" Or ext = ".jpeg" Or ext = ".png" Or ext = ".doc" Or ext = ".txt" Or ext = ".pdf" Then
If hif.Count <= 4 Then
hif.Add(FindFile)
ListBox1.Items.Add(System.IO.Path.GetFileName(FindFile.PostedFile.FileName))
Dim i As String = System.IO.Path.GetFileName(FindFile.PostedFile.FileName)
Else
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "myscript", "alert('Maximum File Limit is 5.');", True)
End If
Else
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "myscript", "alert('Extension of the File is not valid...');", True)
End If
Else
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "myscript", "alert('Choose File to Add...');", True)
End If
End Sub