Upload

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi to all
i want to see a sample in how to uploading file without using <input
type="file"
thanks
 
Why without ?

Other than that you'll have AFAIK to use an ActiveX control, a Java applet
or whatever else...

Patrice
 
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"?

Hans Kesting
 
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 ?)

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



Patrice


--
 
Thanks a lot Patrice
this execption apper when i type file.postedfile.anyThings
realy i dont know how to handles that
 
The content of the form tag is :

<input type="file" id="thisFile" runat="server">
<input type="submit">

The code in page load is :

If IsPostBack Then

thisFile.PostedFile.SaveAs(Server.MapPath("/stockage/fig/test.fil"))
End If

You'll have to replace Server.MapPath with a location that fits your need
(btw is the SavePath initialized).

Does it work ? It works fine here...

Good luck.

Patrice

--
 
Back
Top