if(File.Exists(finalFilePath.ToString()))
{
try
{
HttpContext hc = HttpContext.Current;
hc.Response.Clear();
hc.Response.Charset = ConfigSettings.Create().GetEncoding().ToString();
hc.Response.Buffer= true;
hc.Response.ContentEncoding = ConfigSettings.Create().GetEncoding();
hc.Response.AppendHeader("Content-Disposition","attachment;filename=" + str_fileName.ToString());
hc.Response.WriteFile(finalFilePath.ToString());
hc.Response.Flush();
hc.Response.Close();
}
finally
{
File.Delete(finalFilePath.ToString());
}
}

本文介绍了一种当指定文件存在时通过HTTP进行文件下载的方法。具体步骤包括:检查文件是否存在,设置HTTP响应头,指定字符集及编码,设置文件以附件形式下载,并在发送文件后清理临时文件。

被折叠的 条评论
为什么被折叠?



