I have the following sub for uploading files for my application
Protected Sub UploadBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs)
' Specify the path on the server to
' save the uploaded file to.
Dim savePath As String = "C:\notes\Reports\"
' verify that the FileUpload control contains a file.
If (FileUpload1.HasFile) Then
' Get the name of the file to upload.
Dim fileName As String = Server.HtmlEncode(FileUpload1.FileName)
' Get the extension of the uploaded file.
Dim extension As String = System.IO.Path.GetExtension(fileName)
' Allow only files with .pdf to be uploaded.
If (extension = ".pdf") Then
' Append the name of the file to upload to the path.
savePath += fileName
' Call the SaveAs method to save the
' uploaded file to the specified path.
' If a file with the same name
' already exists in the specified path,
' the uploaded file overwrites it.
' Notify the user that their file was successfully uploaded.
UploadStatusLabel.Text = "Your file was uploaded successfully."
' Notify the user why their file was not uploaded.
UploadStatusLabel.Text = "Your file was not uploaded because " + _
"it is not an 'Adobe PDF' file"
' Notify the user that a file was not uploaded.
UploadStatusLabel.Text = "You did not specify a file to upload."
There is one new condition I want to add besides allowing only pdf files:
I would like the file to be uploaded to have a format like xx_yy_zz, if the condition is not met, the file should not be uploaded. How do I do this.
Secondly, in a situation where a user is trying to upload a file and a similar file already exists, I would like the application to ask/confirm, before over writing the existing file. How do I do this.
Please help this is urgent.