Guest User

Untitled

a guest
Jul 19th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.53 KB | None | 0 0
  1.   try
  2.         {
  3.  
  4.             string PathDownloadImage = ConfigurationManager.AppSettings.Get("PathDownloadImage").ToString();
  5.  
  6.             // string filename = this.Page.Request.QueryString["FileName"].ToString();
  7.  
  8.             int buffersize = 1;
  9.  
  10.             string fileThumbName = "";
  11.  
  12.             if (Request.QueryString["fileThumbName"] != null)
  13.             {
  14.                 fileThumbName = Request.QueryString["fileThumbName"].ToString();
  15.             }
  16.  
  17.             HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(PathDownloadImage + fileThumbName);
  18.             HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
  19.  
  20.  
  21.            // System.IO.FileInfo targetFile = new System.IO.FileInfo(fileThumbName);
  22.  
  23.            
  24.  
  25.             string fullFilePath = Server.MapPath( "Wallpapers/Thumb/" + fileThumbName); //might be you need to change this statement if file does not exist within application folders
  26.  
  27.             System.IO.FileInfo fileInfo = new System.IO.FileInfo(fullFilePath);
  28.  
  29.             Response.Clear();
  30.  
  31.             Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
  32.             Response.AddHeader("Content-Length", fileInfo.Length.ToString());
  33.             Response.ContentType = "application/download";
  34.             //Response.TransmitFile(fileInfo.FullName);
  35.             Response.BinaryWrite(File.ReadAllBytes(fileInfo.FullName));
  36.  
  37.             Response.Flush();
  38.             //Response.Close();
  39.             Response.End();
  40.  
  41.            
  42.  
  43.  
  44.  
  45.  
  46.             //Response.Clear();
  47.             //Response.ContentType = "application/download";
  48.             //Response.AppendHeader("Content-Disposition", ("attachment; filename=" + targetFile.Name));
  49.             //Response.AppendHeader("Content-Length", objResponse.ContentLength.ToString());
  50.  
  51.             //byte[] byteBuffer = new byte[buffersize + 1];
  52.             //MemoryStream memStrm = new MemoryStream(byteBuffer, true);
  53.             //Stream strm = objRequest.GetResponse().GetResponseStream();
  54.             //byte[] bytes = new byte[buffersize + 1];
  55.  
  56.             //while (strm.Read(byteBuffer, 0, byteBuffer.Length) > 0)
  57.             //{
  58.             //    Response.BinaryWrite(memStrm.ToArray());
  59.             //    Response.Flush();
  60.             //}
  61.  
  62.             //Response.Close();
  63.             //Response.End();
  64.             //memStrm.Close();
  65.             //memStrm.Dispose();
  66.             //strm.Dispose();
  67.         }
  68.         catch (Exception ex)
  69.         {
  70.             ex.Message.ToString();
  71.         }
Add Comment
Please, Sign In to add comment