waqas shah

waqas shah

  • 1.3k
  • 78
  • 8k

Cannot download files/images from uploads folder in asp.net

Nov 5 2015 8:02 AM

i explain my issue here  

http://stackoverflow.com/questions/33542421/cannot-download-files-images-from-uploads-folder-in-asp-net/33544472#33544472
 
and also here, i didn't get solution till now, please suggest me for this problem
thanks in advance, 
 
i need to download images that i stored in folder in asp.net web application name as uploads

i got a function that should download this as

private void downloadAnImage(string strImage)
 { 
Response.ContentType = "image/jpg"; 
Response.AppendHeader("Content-Disposition", "attachment; filename=" + strImage); 
Response.TransmitFile(strImage); Response.End();
 }

and i call this function from link button as

protected void lnkDwnSlc_Click(object sender, EventArgs e) 
{ 
if (Session["slc_filepath"] != null) 
{ string path = Server.MapPath(Session["slc_filepath"].ToString());        
  downloadAnImage(path); 
} 
}

where Session["slc_filepath"] is path stored in session

but after running this code file/image is not downloading and I got no error about why file is not downloading. And I checked file path by using breakpoint , it is correct,

I search a lot form google but i can't understand where I missed something.

EDIT: on page load event i pull records from table there i saved path of file and in session i store it like

Session["slc_filepath"] = dt.Rows[0]["UploadSLC"].ToString();

where UploadSLC is column name of table where i store path of image and in database string is looking as

~\uploads\ab071770-473a-4e1a-8cfc-addeccf565d5.jpg

Answers (1)