string FilePath = Server.MapPath(Request.ApplicationPath) + "\\attachment\\" + "20070924661.JPG";
FileInfo fi = new FileInfo(FilePath);
FileStream fs = new FileStream(FilePath, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fi.Name, System.Text.Encoding.UTF8).Replace("+", " "));
Response.BinaryWrite(bytes);
Response.End();
// string att = Server.MapPath(Request.ApplicationPath) + "\\attachment\\" + (string)but.Text;
// Response.Charset = "utf-8";
// Response.Buffer = true;
// this.EnableViewState = false;
// Response.ContentEncoding = System.Text.Encoding.Default;
// Response.AddHeader("Content-Disposition", "attachment; filename=" + but.Text); //' 注意name1 和name de qu别
// Response.ContentType = "application/" + Path.GetExtension(but.Text);
// Response.WriteFile(att);
// Response.End()
浙公网安备 33010602011771号