/// <summary>
/// 文件下载函数
/// </summary>
/// <param name="fileUrl"></param>
/// <returns></returns>
protected Boolean DowmLoad(string fileUrl)
{
Boolean dok = false;
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);
}
return dok;
}
protected void downLoad(int _articleID)
{
Model.mfr_article model = bll.GetModel(_articleID);
if (model.fileName != "")
{
string downfiles = ConfigurationManager.AppSettings["ArticleWord"] + model.fileName;
DowmLoad(downfiles);
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "alert('对不起,文档为空!')", true);
}
}