public void ProcessRequest(HttpContext context) { string imagePath = context.Request.QueryString["image"]; // split the string on periods and read the last element, this is to ensure we have // the right ContentType if the file is named something like "image1.jpg.png" string[] imageArray = imagePath.Split('.'); if (imageArray.Length <= 1) { throw new HttpException(404, "Invalid photo name."); } else { FileStream file = new FileStream(imagePath,FileMode.Open); byte[] buffer = new byte[(int)file.Length]; file.Read(buffer,0,(int)file.Length); file.Close(); context.Response.ContentType = "application/octet-stream"; ////context.Response.AddHeader("content-disposition","attachment context.Response.BinaryWrite(buffer); context.Response.End(); //context.Response.Write(imagePath); //context.Response.ContentType = "image/" + imageArray[imageArray.Length - 1]; //context.Response.WriteFile(imagePath); } } public bool IsReusable { get { return true; } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)