How To Upload A File I am writing an ASP.Net application using Visual Studio.net to upload a file to server and then save it. I draw a 'File Field' HTML object, a label and a button on the web form. The code behind button is as below...
Dim fileName As String
Dim filePath As String
Dim UploadFolder As String = Server.MapPath("tempfiles")
If File1.PostedFile.FileName <> "" Then
fileName = System.IO.Path.GetFileName(File1.PostedFile.FileName)
filePath = UploadFolder & "\" & fileName
File1.PostedFile.SaveAs(filePath)
Label1.Text = "<B>File: " & File1.PostedFile.FileName & "</B>"
Label1.Text = Label1.Text & "<BR>Size: " & File1.PostedFile.ContentLength
Label1.Text = Label1.Text & "<BR>Type: " & File1.PostedFile.ContentType
Label1.Text = Label1.Text & "<BR>Saved As: " & filePath
End If
When I run the application, then the following error is raised....
System.NullReferenceException: Object reference not set to an instance of an object.
... and the line number is that having the 'if' statement.
CAN ANY BODY HELP ME WHAT IS THE PROBLEM... Thanks a lot
NOTE: The form in HTML mode is like
<form id="Form1" ENCTYPE=”multipart” runat="server"> |