tags:

views:

263

answers:

3

Hi,

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.

A: 

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

Kirtan
+1  A: 

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.

Mitch Wheat
A: 

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.

Olivier PAYEN

related questions