all groups > asp.net building controls > august 2005 >
You're in the

asp.net building controls

group:

Making sure a file exists before uploading it


Re: Making sure a file exists before uploading it 
8/20/2005 11:12:59 PM
asp.net building controls:
| I use an If statement to make sure something is there, but I want to make
| sure the file that it refers to is actually there before trying to perform
| the upload. How can I do this? The fact that it is sometimes hard to look
at
| the client's hard drive (due to security reasons) I do not know how to
make
| sure the file actually exists, and I want to do everything possible to
| prevent my users from seeing error messages. Thanks.

it really doesn't matter whether you check before-hand or when you actually
run your upload code that assumes it is a valid, file-containing
upload...either way, the user is going to, or should, be shown some kind of
error message to the effect that they are trying to do something that "just
ain't right". in fact, they would probably feel a little more assured if
they got confirmation of the upload when it was successful as well.

your desire to anticipate the user's experience is a very good aim. i think
pragmatism will win out here though, where confirmation of successful or
failing uploads that are adequately descriptive will be a good thing for the
user and a more straightforward programatic approach for you.

hth,

me

Making sure a file exists before uploading it Nathan Sokalski
8/20/2005 11:15:15 PM
I have a form that allows the user to upload a file. Even though <input
type="file" runat="server"> is intended to have the user choose the file
using the browse button, it still allows them to change the path before it
is uploaded. I currently use the following code to upload the file:
Dim upfilename As String = ""

If fileDetails.Value <> "" Then

Dim dir As String() =
fileDetails.PostedFile.FileName.Split("\".ToCharArray())

upfilename = dir(dir.GetUpperBound(0))

fileDetails.PostedFile.SaveAs(Server.MapPath("/") & upfilename)

End If

I use an If statement to make sure something is there, but I want to make
sure the file that it refers to is actually there before trying to perform
the upload. How can I do this? The fact that it is sometimes hard to look at
the client's hard drive (due to security reasons) I do not know how to make
sure the file actually exists, and I want to do everything possible to
prevent my users from seeing error messages. Thanks.
--
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

AddThis Social Bookmark Button