File download using C#

You would have tried downloading a file from the Internet. And, one of the following would have happened: 1. the “Save As” dialog box will show from where you can choose to save the file, or 2. the file will be opened in the web browser itself. The latter happens because the application that normally is used to open the file would have been installed on the machine. What if we wanted to show the “Save As” dialog box in any case? Use “Response.AddHeader” If a string con …

You would have tried downloading a file from the Internet. And, one of the following would have happened: 1. the “Save As” dialog box will show from where you can choose to save the file, or 2. the file will be opened in the web browser itself. The latter happens because the application that normally is used to open the file would have been installed on the machine. What if we wanted to show the “Save As” dialog box in any case? Use “Response.AddHeader” If a string contains special characters we should either use the “Escape sequence” or the “Verbatim string”. Note that in the example below I have used the “Verbatim String” character (i.e., @) in the line where I open a FileStream. [bold]The complete code listing follows:[/bold] [code] <%@ Page Language="C#" %> <%@ Import Namespace="System.IO" %>
[/code]

One thought on “File download using C#

[gp-comments width="770" linklove="off" ]