Click here to Skip to main content
15,892,927 members

Comments by ErikVabo (Top 3 by date)

ErikVabo 28-Jul-14 7:58am View    
All the files are now called FileName.pdf, but forgot to say, it is not only pdf files, det are different types such as .tiff
ErikVabo 28-Jul-14 6:55am View    
If I delete MapPath it works! There is only one thing, all the files I download are named "downloadfile.aspx", "downloadfile.aspx (1)" and the files are originally pdf files, so in order of them to work I need to change the name from .aspx to .pdf, is there anyway I can avoid this? So the filename and type is alike the file I download?
ErikVabo 28-Jul-14 6:17am View    
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Download")
{
string Filepath = e.CommandArgument.ToString();
string path = MapPath(Filepath);
byte[] bts = System.IO.File.ReadAllBytes(path);


Response.Clear();
Response.ClearHeaders();
Response.AddHeader("Content-type", "application/octect-stream");
Response.AddHeader("Content-Length", bts.Length.ToString());
Response.AddHeader("Content-Disposition", "attachment; Filepath=" + Filepath);
Response.BinaryWrite(bts);
Response.Flush();
Response.End();
}
}

Having the same problem, how can I fix this?