我是这样写的:
public void ProcessRequest(HttpContext context)
{
if ((context.Request.QueryString["t"] != null) && (context.Request.QueryString["path"] != null))
{
context.Response.ContentType = GetMimeType(context.Request.QueryString["t"]);
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.BufferOutput = false;
context.Response.WriteFile("uppic\\" + context.Request.QueryString["path"]);
}
}
这样直接把图片显示在浏览器中了,我需要是直接提示用户另存图片。
试一下用流来实现
FileStream fs = new FileStream(strFilePath, 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(fileName, System.Text.Encoding.UTF8));
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();