我正在通过 C# ASPX 页面下载文件。该文件以temp\GUID\file.zip形式在 URL 文件参数中传递。我的代码:
void Page_Load(object sender, EventArgs e)
{
if (!this.Page.IsPostBack)
{
if (Request.QueryString["File"] != null)
{
Response.BufferOutput = true;
if (Request.QueryString["File"].Contains( "zip" ))
Response.ContentType = "application/zip"; //varies depending on the file being streamed
Response.AddHeader( "Content-Disposition", "attachment; filename=\"" + Request.QueryString["File"] + "\"" );
Response.WriteFile( Server.MapPath( Request.QueryString["File"] ) );
}
}
}
问题是,该文件在我的下载目录中显示为tempguidfile
(例如:temp07e315af-13c6-4537-92df-fae95cc0039fFile.zip)。我如何获得Response.Writefile()
,TransmitFile()
或类似的东西以将文件简单地保存为File.zip在 Downloads 目录中?