开发者

ASP.net attachment then refresh page

开发者 https://www.devze.com 2022-12-11 16:05 出处:网络
I am working on a c# project using ASP .net. I have a list of reports with a hyperlink for each, which calls the web server, retrieves

I am working on a c# project using ASP .net.

I have a list of reports with a hyperlink for each, which calls the web server, retrieves a PDF and then returns the PDF for the user to save or open:

ASPX page:

<table>
<tr>
<td>
    <a href="#" onclick="SubmitFormToOpenReport();">Open Report 1</a>
<td>
</tr>
...
</table>

ASP.Net:

context.Response.Clear();
context.Response.AddHeader("content-disposition", "attachment;fil开发者_如何学运维ename=report.pdf");
context.Response.Charset = "";
context.Response.ContentType = "application/pdf";
context.Response.BinaryWrite(myReport);
context.Response.Flush();

This works as expected, however I would like it to also refresh the page with an updated list.

I am having trouble as the single request/response is returning the report.

Is there a way to refresh the page as well?

While there is a correct response, feel free to include answers which details alternative solutions/ideas for doing this.


Unfortunately your current approach is a dead end. The nature of HTTP is single request, single response. A response can only have one code - "OK, here is some data, please download it". "Go here instead" is a different code. You're describing something much more complex - a sequence of instructions. First "here is a file", then "redirect yourself to another resource". The implications of making this work should be a clue - when should the browser redirect? When the user selects a location to save the file? After the file is finished downloading?

To do what you're describing, you could have the JavaScript open the PDF in a new window and also re-load the current window.


Try using response.redirect(request.url.tostring) after your context.Response.Flush();

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号