Downloading

K

Kenneth Windish

Hi,

This has probably been discussed before, but I have been unable to find
anything on it, except an article written in C or C+, or C# and not in VB.

How can I download a file from my web page to a client?

Thanks in advance.

Ken
 
G

Guest

Dear kan,

There are many ways to download a web file (remote file). The best way, i
ever invent in dotnet is to do it with webclient object.

This object provides you many methods for download data, you can also
download a file as a data or can also download file using
webclient.DownloadData(URL) method or DownloadFile(URL).

In C# or vb.net you can use this. The other thing, you can also provide
credential for those web location which have some authentication, windows or
whatever.
 
M

Mona

Hi Kenneth,

In order to download files to a user machine you can use the following code snippet to do so:

Dim FilePath As String = Server.MapPath("abc.txt")
& nbsp;Dim TargetFile As New System.IO.FileInfo(FilePath)

' clear the current output content from the buffer
Response.Clear()
' add the header that specifies the default filename for the Download/
' SaveAs dialog
Response.AddHeader("Content-Disposition", "attachment; filename=" + _
TargetFile.Name)
' add the header that specifies the file size, so that the browser
' can show the download progress
Response.AddHeader("Content-Length", TargetFile.Length.ToString())
' specify that the response is a stream that cannot be read by the
' client and must be downloaded
Response.ContentType = "application/octet-stream"
' send the file stream to the client
Response.WriteFile(TargetFile.FullName)
' stop the execution of this page
Response.End()

HTH

Mona[Grapecity]
 
K

Kenneth Windish

Hi,

That's exactly what I needed and it works great.
Thanks for the help.

Ken



Hi Kenneth,

In order to download files to a user machine you can use the following code snippet to do so:

Dim FilePath As String = Server.MapPath("abc.txt")
& nbsp;Dim TargetFile As New System.IO.FileInfo(FilePath)

' clear the current output content from the buffer
Response.Clear()
' add the header that specifies the default filename for the Download/
' SaveAs dialog
Response.AddHeader("Content-Disposition", "attachment; filename=" + _
TargetFile.Name)
' add the header that specifies the file size, so that the browser
' can show the download progress
Response.AddHeader("Content-Length", TargetFile.Length.ToString())
' specify that the response is a stream that cannot be read by the
' client and must be downloaded
Response.ContentType = "application/octet-stream"
' send the file stream to the client
Response.WriteFile(TargetFile.FullName)
' stop the execution of this page
Response.End()

HTH

Mona[Grapecity]
 
K

Kenneth Windish

Hi,

Whew. My heads still spinning. Web Client objects..... sounds pretty
complicated. Thanks for the info though, might look into out of curiosity.

Later

Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,141
Latest member
BlissKeto
Top