thanks Patrice i use <input file
but the code dosent work my code :
''''''''''''''''''''''''''''''
Sub Upload_Click(source As Object, e As EventArgs)
If Not (uploadedFile.PostedFile Is Nothing) Then
Try
Dim postedFile = uploadedFile.PostedFile
Dim filename As String = Path.GetFileName(postedFile.FileName)
Dim contentType As String = postedFile.ContentType
Dim contentLength As Integer = postedFile.ContentLength
postedFile.SaveAs(savePath & filename)
message.Text = postedFile.Filename & " uploaded" & _
"<br>content type: " & contentType & _
"<br>content length: " & contentLength.ToString()
Catch exc As Exception
message.Text = "Failed uploading file"
End Try
End If
End Sub
What do you mean by "doesn't work"?
* do you get any errors?
* if so, what errors?
* if you get the message "Failed ..", what exactly is the Exception?
(use debugger or add text to message)
a guess: do you (or rather the aspnet user) have permission to write
to the "savepath"?
Sorry I thought you meant "without". I would start by removing the exception
check to see what is the real error.
My perosnal preference is mot often to use Request.Files that is the
collection of posted files rather than the control itself but it shouldn't
make a great difference.
See also if enctype="multipart/form-data" on the from tag helps (someone
else told it was taken care automatically but who knows ?)
Thanks Patrice
the problem in this line
UploadedFile.PostedFile.SaveAs(savePath)
the execption is : System.NullReferenceException: Object reference not set
to an instance of an object.
Ok, the line you mention doesn't match the code you posted first.
Is UploadedFile nothing ? If yes the control is not declared properly.
Is PostedFile Nothing ? If yes the file is not posted. Try
Request.Files.Count.
If it's still fails, there is likely a problem in the client side code
(perhaps the enctype thing ?)...