File upload feature in ASP.NET
I have used the file upload feature in ASP.NET. If users use the Browse button next to the text box and select the file they want, there is no problem uploading the file.
But instead, if they type the file name directly into the text box instead of using the Browse button, I have to check if the file actually exists on the client machine.
Please note that I am NOT trying to check if a file exists on the server, I want some function to allow me to check the user's local machine if a file exists or not.
if someone like an idea helped me a lot.
a source to share
You don't have to worry about whether the file was specified via the Browse button or via text input, because this is handled by the browser itself (rendering of the input type file does not match different browsers).
Instead, you check if the file has been published by the browser with
FileUpload.HasFile
the properties of the ASP.NET FileUpload control.
a source to share
As @kirtan says, you should prevent the user from selecting the file using Browse.
You tried:
'' Before attempting to save the file, verify
'' that the FileUpload control contains a file.
If (FileUpload1.HasFile) Then
'' Call a helper method routine to save the file.
SaveFile(FileUpload1.PostedFile)
Else
'' Notify the user that a file was not uploaded.
UploadStatusLabel.Text = "You did not specify a file to upload."
End If
From here .
a source to share
Ideally, letting the user enter a filename to upload will not work in most browsers. And it shouldn't be. The user is not allowed to enter anything into the input field of the download control.
And luckily, there is no method you can use to check if a file exists on the user's filesystem or not (they did exist in the old days).
a source to share