如何使用窗体表单Web浏览器禁用保存对话框。 [英] How to disable save dialog box using window form web browser.

查看:65
本文介绍了如何使用窗体表单Web浏览器禁用保存对话框。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我陷入困境,我一直在寻找答案,我找不到符合我要求的答案。我不知道该怎么做。我没有任何代码,因为我不知道这是否可行。



我在网站上有用户访问权限然后有一个按钮,一旦我点击文件它将下载,并将显示保存对话框,询问文件夹位置。该文件没有链接或地址。我认为一旦点击excel按钮就会在后端创建它。



现在我的问题是,如何在单击按钮excel后不下载excel文件使用Windows窗体的Web浏览器保存对话框?或者,如果那是不可能的。如何在保存对话框中自动单击保存按钮,然后自动化文件夹位置。



我尝试过:



我尝试过研究,但仍然无法找到适合我桌面应用程序的代码

Im stuck, I been looking for an answer for days now and I cant find any answer that fits my requirements. I dont know how to do it. I dont have any code yet since I dont know if this is possible.

I have a user access on the website then there is a button that once I click the file it will download, and the save dialog box will display asking for a folder location. The file doesnt have a link or an address. I think its created in the backend once the excel button is click.

Now my question is, how can I download the excel file after I click the button excel without displaying the save dialog box using windows form web browser? Or if that’s not possible. How can I click the save button automatically on the save dialog box then automate the folder location.

What I have tried:

I tried researching and I still cant find the right code for my desktop app

推荐答案

如果我的下载页面是像这样;



If my download page is like this;

<asp:Button ID="btnDownload" runat="server" Text="Download" OnClick="btnDownload_Click" />





代码隐藏





code-behind

protected void btnDownload_Click(object sender, EventArgs e)
{
    string path = "~/files/pic.png";
    Response.Clear();
    Response.Buffer = true;
    Response.AddHeader("content-disposition", String.Format("attachment;filename={0}", Path.GetFileName(path)));
    Response.ContentType = "application/octet-stream";
    Response.BinaryWrite(File.ReadAllBytes(Server.MapPath(path)));
    Response.Flush();
    Response.End();
}





所以点击下载按钮会导致代码将files / pic.png文件写入客户端在浏览器中触发下载。如果我看一下Fiddler中的请求就是这个url





So clicking the download button causes the code to write the files/pic.png file to the client and it triggers a download in the browser. If I look at the request in Fiddler it is to this url

http://localhost:50725/Default.aspx





和帖子数据是这样的;





and the post data is like this;

__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=D2GscibKx2pwUA ...





这是页面上的表格值。发布数据的重要部分是告诉asp.net已点击下载按钮,这就是这个





That's the form values on the page. The important bit of post data is the bit that tells asp.net that the download button has been clicked, that's this

ctl00%24MainContent%24btnDownload=Download





如果我查看我的页面来源,我看到我的下载按钮被称为ctl00



If I view the source of my page I see my download button is called "ctl00

MainContent
MainContent


btnDownload(它使用的主页是错误的名字)。所以我想在帖子数据中使用POST发送到该URL,这将使asp.net认为请求来自浏览器点击下载按钮,所以我只是抓住响应并将其保存到文件中;



btnDownload" (it's using master pages ergo the weird name). So I want to POST to that url with that in the post data and that will make asp.net think the request has come from a browser clicking the download button, so I just grab the response and save it to a file;

string url = "http://localhost:50725/Default.aspx";

NameValueCollection data = new NameValueCollection();
// data.Add("__EVENTTARGET", ""); // you can add any post data as needed
data.Add("ctl00


这篇关于如何使用窗体表单Web浏览器禁用保存对话框。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆