Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try
- {
- string PathDownloadImage = ConfigurationManager.AppSettings.Get("PathDownloadImage").ToString();
- // string filename = this.Page.Request.QueryString["FileName"].ToString();
- int buffersize = 1;
- string fileThumbName = "";
- if (Request.QueryString["fileThumbName"] != null)
- {
- fileThumbName = Request.QueryString["fileThumbName"].ToString();
- }
- HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(PathDownloadImage + fileThumbName);
- HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
- // System.IO.FileInfo targetFile = new System.IO.FileInfo(fileThumbName);
- string fullFilePath = Server.MapPath( "Wallpapers/Thumb/" + fileThumbName); //might be you need to change this statement if file does not exist within application folders
- System.IO.FileInfo fileInfo = new System.IO.FileInfo(fullFilePath);
- Response.Clear();
- Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
- Response.AddHeader("Content-Length", fileInfo.Length.ToString());
- Response.ContentType = "application/download";
- //Response.TransmitFile(fileInfo.FullName);
- Response.BinaryWrite(File.ReadAllBytes(fileInfo.FullName));
- Response.Flush();
- //Response.Close();
- Response.End();
- //Response.Clear();
- //Response.ContentType = "application/download";
- //Response.AppendHeader("Content-Disposition", ("attachment; filename=" + targetFile.Name));
- //Response.AppendHeader("Content-Length", objResponse.ContentLength.ToString());
- //byte[] byteBuffer = new byte[buffersize + 1];
- //MemoryStream memStrm = new MemoryStream(byteBuffer, true);
- //Stream strm = objRequest.GetResponse().GetResponseStream();
- //byte[] bytes = new byte[buffersize + 1];
- //while (strm.Read(byteBuffer, 0, byteBuffer.Length) > 0)
- //{
- // Response.BinaryWrite(memStrm.ToArray());
- // Response.Flush();
- //}
- //Response.Close();
- //Response.End();
- //memStrm.Close();
- //memStrm.Dispose();
- //strm.Dispose();
- }
- catch (Exception ex)
- {
- ex.Message.ToString();
- }
Add Comment
Please, Sign In to add comment