PROWAREtech

articles » archived » asp-net » download-files

ASP.NET: Download Files

How to download files to the browser from the server using Web Forms (.NET Framework).

Download any file type from a web form in ASP.NET. This example downloads zip files.

<%@ Page Language="C#" ContentType="application/x-zip-compressed" %>
<%
	Response.Clear();
	Response.AppendHeader("content-disposition", "attachment;filename=" + Request.QueryString["file"]);
	string file = Server.MapPath("/zipfiles/" + Request.QueryString["file"].Replace("../", ""));
	Response.WriteFile(file);
	Response.End();
%>


This site uses cookies. Cookies are simple text files stored on the user's computer. They are used for adding features and security to this site. Read the privacy policy.
CLOSE