string fileurl="xx.htm";
string xurl=Server.MapPath("/userfiles/"+fileurl.ToString());
System.IO.FileInfo file = new System.IO.FileInfo(xurl);
if(file.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Filter.Close();
Response.WriteFile(file.FullName);
Response.End();
}
else
{
Response.Write("文件不存在");
Response.End();
}
文章来源:http://blog.163.com/asd119_cn/blog/static/11973332006101083359201