Say I have a server that returns a link. the link is a link to an excel file. Now I want to download that file and save it to my local pc by poping a save dailog box.
I have the following codes but it's not working. It's not poping up the save dialog box and it's not saving the file.
try
{
string filepath = Server.MapPath("~/Images/0ca66926-6977-43d3-9c97-f84a43f6ce5d.xls"); // supply the return link
FileInfo myfile = new FileInfo(filepath);
if (myfile.Exists)
{
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment; filename=" + myfile.Name);
Response.AddHeader("Content-Length", myfile.Length.ToString());
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.WriteFile(myfile.FullName);
Response.End();
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}