c# 文件,图片 下载

来源:互联网 发布:java 多线程的生命 编辑:程序博客网 时间:2024/05/11 01:59

 

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);
        }

 

原创粉丝点击