down下载

 if (!Page.IsPostBack)
        {
            string address = Request["address"].ToString();
            //string httpaddr="files/"+address;
            address = Server.MapPath("files/") + address;
            //Response.Write(address);

            System.IO.FileInfo fi = new System.IO.FileInfo(address);
            if (System.IO.File.Exists(address))
            {
                Response.Clear();
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(fi.Name));
                Response.AddHeader("Content-Length", fi.Length.ToString());
                Response.ContentType = "application/octet-stream";
                Response.Filter.Close();
                Response.WriteFile(fi.FullName);
                Response.End();
                //Response.WriteFile(httpaddr);
                //Response.Write();
            }
            else
            {
                Response.Write("<script>alert('文件不存在!')</script>");
            }
        }

你可能感兴趣的:(down下载)