try
{
string fullPathUrl = Server.MapPath(fileUrl);//获取下载文件的路劲
System.IO.FileInfo file = new System.IO.FileInfo(fullPathUrl);
if (file.Exists)//判断文件是否存在
{
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.AddHeader("content-disposition", "attachment;filename=" +file.Name);
Response.AddHeader("cintent_length", "attachment;filename=" + HttpUtility.UrlDecode(file.Name));
Response.AddHeader("cintent_length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName);//通过response对象,执行下载操作
Response.Flush();
Response.End();
dok = true;
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "dd", "alert('文件不存在')", true);
}
}
catch
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "dd", "alert('文件不存在')", true);
}