开发者

Asp.Net initiate transfer of 2 files with 'Save as' dialog

开发者 https://www.devze.com 2023-01-05 21:23 出处:网络
protected void Button1_Click(object sender, EventArgs e) { Response.ContentType = \"text/txt\"; Response.AppendHeader(\"Content-Disposition\", \"attachment; filename=\" + \"file.txt\");
protected void Button1_Click(object sender, EventArgs e)
        {
            Response.ContentType = "text/txt";
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + "file.txt");
            Response.Write(@"C:\temp.txt");
            Response.End();
        }

Hi, the previous code allows me to transfer one file within one click by popping up the 'Save as' dialog box.

I would like to transfer 2 files within on click by popping up 2 'Save as' dialog boxes

I might ha开发者_Go百科ve a too simplistic approach because the below doesn't work, it just brings one 'Save as' box

protected void Button1_Click(object sender, EventArgs e)
        {
            Response.ContentType = "text/txt";
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + "file.txt");
            Response.Write(@"C:\temp.txt");
            Response.End();

            Response.ContentType = "text/txt";
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + "file.txt");
            Response.Write(@"C:\temp.txt");
            Response.End();
        }

Thanks for your help!


Well, you can't give more than one response to a request. You need to work out a way to initiate two requests from the browser. The first thought that comes to mind is two javascript window.open calls


I don't think it's possible to achieve this directly, but you can manage it with a workaround.

Create two iframes on your page. Once the user clicks your button, use javascript to change the src of the iframes to an aspx page which servers up one file each to be saved.

I haven't tried it, but I think it should work.

0

精彩评论

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

关注公众号