Download from a webpage

  • Thread starter Thread starter Nikolay Petrov
  • Start date Start date
N

Nikolay Petrov

how to initiate a file download from an asp .net page?

thanks
 
if I use the WebClient, will it use the current configuration from the
browser, like proxy, cookies and other session specific information?
 
can I use Response.WriteFile

after testing an strange effect occured, instead initiating donwload,
the contents of the file are displayed in the browser window
 
Nikolay,

Can you do it with that acknowledge?
That is very normal by the way.

(The redirect what you see is the normal situation)


Cor
 
thanks for efforts, i've managed to find a way:

Dim filename As String = "C:\SomeFile.txt"
Dim FS As FileStream = New FileStream(filename, FileMode.Open)
Dim iFullSize As Integer = FS.Length
Response.Clear()
Response.AddHeader("Content-Type", "binary/octet-stream")
Response.AddHeader("Content-Disposition", _
"attachment; filename=DownloadedImage.txt; size=" _
+ iFullSize.ToString())
Response.AddHeader("Content-Length", iFullSize.ToString())
Response.Flush()
Dim chunkSize As Integer = 1024
Dim i As Integer
For i = 0 To iFullSize Step chunkSize
' Everytime check to see if the browser is still connected
If (Not Response.IsClientConnected) Then
Exit For
End If
Dim size As Integer = chunkSize
If (i + chunkSize >= iFullSize) Then
size = (iFullSize - i)
End If

Dim chunk(size - 1) As Byte
FS.Read(chunk, 0, size)
Response.BinaryWrite(chunk)
Response.Flush()
Next
FS.Close()
 

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

Back
Top