Last post Nov 19, 2008 01:05 AM by Dino624
Nov 22, 2007 10:25 PM|hypercode|LINK
I need some help with allowing client to download a file from the server. Runng ASP.Net 2.0, VB.Net, WS2003, IIS 6 and .Net Framework 2.0.
Do I need to add the line "Response.Flush()" in this code block? I know that it will send all buffered content to the client. Is "Response.Flush()" necessary here?
Also, do you have any suggestions for improving this code block?
I appeciate your input and Thanks!
Nov 22, 2007 10:46 PM|mbanavige|LINK
Response.Flush is called by the Response.End method so it is not explicitly required.
Finding answers to questions like this can be aided by the use of
Reflector. It's one of my highly recommended downloads.
Nov 23, 2007 12:59 AM|folkertsj|LINK
This Should help...
Dim DownloadPath As String = "e:\myFolder\" + fileName
HttpContext.Current.Response.ContentType = "application/octet-stream"
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"")
Nov 23, 2007 06:19 AM|hypercode|LINK
Thanks guys for your input!
folkertsj, Do you have an extra quote in there. and why should I put a "\" at the end of the filename?
It's working without "attachment;"
What does "attachment;" do for the Response.Addheader?
Nov 26, 2007 02:11 AM|Thomas Sun – MSFT|LINK
Based on my understanding, you want to download the file to client from server using Response objects. If I have misunderstood you, please feel free to let me know.
In this case (Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"")), we add the \" to change the file name to “filename” format. We can customize the file name that is displayed in the File Download dialog box.
Attachment - forces download, inline - forces the browser to open the content inline if possible. For more information, see
I hope this helps.
Nov 26, 2007 02:47 AM|hypercode|LINK
Thanks guys for pitching in! Correct, the file gets downloaded from the server via a Button Click.
At this point I'm using this code and it appears to work. The file downloads.
Dim theFileName As
String = TextBox1.Text
Dim thePath As
String = "e:\myFolder\" & fileName
Response.ContentType = "application/octet-stream"
"attachment; filename=" + theFileName)
When I run the Sub with this code, the File Download Dialog Opens:
Info displayed is:
Type: Unknown File Type 40Kb
From: The IP address
I get options to "Find", "Save" or "Cancel
I'm still not sure what you mean with the explanation of why "\" is used. If you can expand on this, I'd be grateful.
Nov 26, 2007 07:08 AM|Thomas Sun – MSFT|LINK
Thanks for your response.
For example, when we use the “\" in the string strValue = "\"test \"" express, the value of strValue is
We don’t need to use “\" in this case. We just need to assign the file name just like you did.
I hope this helps.
Sep 29, 2008 02:42 PM|wtct|LINK
I have written some code like below for client's downloading files:
ImageButton btnDownloadFile = (ImageButton)sender;
FileInfo OutFile = new FileInfo(MapPath(btnDownloadFile.CommandArgument));
"attachment;filename=" + OutFile.Name);
Response.ContentType = "application/x-zip-compressed";
When OutFile.Name string includes polish special characters, then in download browser's box appears nonsense characters of file name to download.
How can I fix it?
Nov 18, 2008 01:39 PM|mqpasta|LINK
what if I want to download multiple files in one response?
Nov 19, 2008 01:05 AM|Dino624|LINK
I am trying to download a file from our server that contains multiple '.' ex: my.pc.file.txt
It is replacing the first '.' with
Is there any way to bypass this?
I do not have any control over the file naming.