InterviewSolution
Saved Bookmarks
| 1. |
Solve : FILE UPLOAD (VS 2003)? |
|
Answer» HI guys, I have huge web App, one of the functions is to upload FILES, so it works fine, My PROBLEM is, if you try to upload a file that already exist (has the same File name) it will overwrite the one. So what i want is, before the file is saved, check if that name exists, if it does then display (ERROR: the file you are trying to upload, already exist please rename you file or it will over RIGHT the existing one and data will be lost.). My code Private Sub btn_Attach_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Attach.Click If Not in_FileName.PostedFile Is Nothing And in_FileName.PostedFile.ContentLength > 0 Then Dim fn As String = System.IO.Path.GetFileName(in_FileName.PostedFile.FileName) Dim SaveLocation As String = Server.MapPath("Data") & "\" & fn Try in_FileName.PostedFile.SaveAs(SaveLocation) lbl_attachmessage.Text = "The file has been uploaded...!!!" Catch ex As Exception Response.Write("Error:" & ex.Message) End Try Else lbl_attachmessage.Text = "Please select a file to upload...!!!" End If |
|