Question Why does File Browse field return a "null"?

avvee

New member
Joined
Apr 19, 2009
Messages
1
Programming Experience
Beginner
Hello,

i have a problem here i really hope someone can help me with or give me some advice.

I am writing a script that allows users to browse for an image and uploads the images. After that it will write the path of the uploaded image path into a database.

This is the snippet of the code where i cam trying to get the filename of the chosen file and putting it into a string:

Try
strFileName = File1.PostedFile.FileName
strFileName2 = File2.PostedFile.FileName
strFileName3 = File3.PostedFile.FileName
c = System.IO.Path.GetFileName(strFileName)
c2 = System.IO.Path.GetFileName(strFileName2)
c3 = System.IO.Path.GetFileName(strFileName3)

however i get this error :

System.NullReferenceException: Object reference not set to an instance of an object.
at _Default.Button1_Click(Object sender, EventArgs e) in D:\Inetpub\httpdocs\CreatePro.aspx.vb:line 101

the line 101 refers to : "strFileName = File1.PostedFile.FileName"

Can anyone advise me what's wrong and how to fix it ?

thanks in advance!
 
Back
Top