0

I was using a File Upload functionality in ASP.NET .If the users are using the Browse button shown next to the textbox and selecting the required file then there is no issue about the file getting upload.

But instead if they are directly typing the file name in the textbox instead of using the Browse button then I should be able to check if really the file exist in the client machine.

Please note that I am NOT trying to check if the file exist in ther Server, I want some function that would let me check in the local machine of the user whether the file exist or not.

if somebody as an idea it would be of great help to me.

3 Answers 3

1

You shouldn't have to care if the file was specified using the Browse button or via the text input, because this is handled by the browser itself (the rendering of the input type file is not the same across the different browsers).

Instead, you shoud check if a file was posted by the browser using the

FileUpload.HasFile

property of the FileUpload ASP.NET Control.

Sign up to request clarification or add additional context in comments.

Comments

1

As @kirtan says, you should restrict the user to pick a file using Browse.

Have 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.

Comments

0

Ideally, allowing a user to enter the file name for upload won't work on most browsers. And this must not be done. The user must not be allowed to type anything in the input box of the upload control.

And, fortunately there's no method which you can use to check whether a file exists on the user's file system or not (They used to exist in the older days).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.