I am just wanting to drop a pdf file in a folder in my solution and let users download it on my site. Pretty simple!
I have a main .aspx page that contains a static link to another .aspx page that I am using just for downloading a file. The code works if I run the download page directly out of visual studio however if I run my main page and click the that I have pointing to this page it does not work. Here's the code for the download page:
FileInfo file = new FileInfo(Server.MapPath("~/Workflow/Workflow v3.pdf"));
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/pdf";;
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Response.BinaryWrite((byte[])File.ReadAllBytes(Server.MapPath("~/Workflow/Workflow v3.pdf")));
Response.Flush();
Response.End();
And just for reference.. here is another download page I am using in a different area of my tool. This page actually takes a parameter and hits the database to grab files stored in a database. This code DOES work, but I don't want to do it this way for my "workflow" download page.
...
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = AgreementDocumentTable.Rows[0]["ContentType"].ToString();
Response.AppendHeader("Content-Disposition", "attachment; filename=" + AgreementDocumentTable.Rows[0]["Title"].ToString());
Response.BinaryWrite((byte[])AgreementDocumentTable.Rows[0]["AgreementDocument"]);
Response.Flush();
Response.End();