G
Guest
Hello
I am trying to return the contents of an Excel file. However, I don't want to just redirect the request to the Excel file since it does not reside in a location where that is appropriate. I am trying to write the contents of the file to the response but am having trouble. My code resides in the handler for a link-button's click event
Response.ClearHeaders()
Response.ClearContent()
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-Disposition", "attachment;filename=" + filename + ".XLS")
Response.WriteFile(path)
Response.Flush()
Response.End()
This almost works. When I run it, I get two dialog boxes asking if I want to open or save filename.xls. If I click 'Open' on both, Excel opens up (external from the browser) with the file in it. When I take out the "attachment" designation in the header, I only get 1 dialog box but, if I click 'Open', it ends up displaying the login page of my site in Excel within my browser --- I assume that it is failing some kind of security check or it is being interrpreted as an unauthenticated user at that point
What am I doing wrong? I don't like the two dialog boxes I receive with the code above (and I am sure one of them is resulting in the same behavior of returning the start-page which isn't so good). And, I would prefer that Excel open embedded in the browser instead of in stand-alone mode (although, at this point I would take either behvaior to avoid the second dialog box)
Thanks for any assistance!
I am trying to return the contents of an Excel file. However, I don't want to just redirect the request to the Excel file since it does not reside in a location where that is appropriate. I am trying to write the contents of the file to the response but am having trouble. My code resides in the handler for a link-button's click event
Response.ClearHeaders()
Response.ClearContent()
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-Disposition", "attachment;filename=" + filename + ".XLS")
Response.WriteFile(path)
Response.Flush()
Response.End()
This almost works. When I run it, I get two dialog boxes asking if I want to open or save filename.xls. If I click 'Open' on both, Excel opens up (external from the browser) with the file in it. When I take out the "attachment" designation in the header, I only get 1 dialog box but, if I click 'Open', it ends up displaying the login page of my site in Excel within my browser --- I assume that it is failing some kind of security check or it is being interrpreted as an unauthenticated user at that point
What am I doing wrong? I don't like the two dialog boxes I receive with the code above (and I am sure one of them is resulting in the same behavior of returning the start-page which isn't so good). And, I would prefer that Excel open embedded in the browser instead of in stand-alone mode (although, at this point I would take either behvaior to avoid the second dialog box)
Thanks for any assistance!