在VB中从Web浏览器下载保存为对话框的文件 [英] File download with save as dialog box from web browser in VB

查看:198
本文介绍了在VB中从Web浏览器下载保存为对话框的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All



如何在Internet Explorer中下载对话框vb



我尝试了什么:



我试图在谷歌搜索很多但没有找到任何好的解决方案。

Hello All

How to file download Dialog in Internet Explorer in vb

What I have tried:

I tried to search on google a lot but not found any good solution.

推荐答案

你不能在Web浏览器中真正打开文件下载对话框,因为它实际上无法直接访问服务器文件夹 - 或者至少它不应该。



相反,您必须创建一个列出文件夹及其内容的网页,并向用户显示。当他们选择一个文件时,你可以将文件发送给他们,但是之后你无法控制它发生了什么 - 你不能强制浏览器保存它,或者说如果用户选择它应该保存在哪里要做到这一点。
You can't really "Open a file download dialog" in a web browser because it doesn't really have direct access to the server folders - or at least it shouldn't.

Instead you would have to create a webpage which listed the folders and their content and show that to the user. when they select a file, you can send the file to them, but you will have no control over what happens to it after that - you can't force the browser to save it, or say where it should be saved if the user chooses to do that.


这取决于你的技能,如jquery,javascript等前端技术。



1)你可以创建一个文件列表

2)在那里设置下载按钮或链接

3)你可以使用模态弹出窗口或任何div(fadeIn / fadeOut)作为对话和你可以根据你的需要写一个逻辑。

4)你可以点击对话的动作下载文件



休息,你对浏览器的本机行为没有任何命令。
It is depending upon your skill over frontend side technologies like jquery, javascript.

1) You can create a list of files
2) Set download button or link over there
3) You can use modal popup or any div (fadeIn/fadeOut) as a dialogue and you can write a logic according to your need.
4) You can download the file on click of actions of a dialogue

Rest, You don't have any command over browser's native behavior.


Nirav,如果我理解正确,你想将.XLSX文件从服务器发送到浏览器,但要给用户保存文件而不是在Excel中自动打开文件的选项?

如果是这样的话在这种情况下,然后在服务器端的VB.Net代码中执行以下操作:

Nirav, if I understand correctly, you want to send the .XLSX file from the server to the browser, but to give the user the option to SAVE the file rather than have it automatically open in Excel?
If that's the case, then in your server-side VB.Net code, do something like:
Dim filename as string = "demo.xlsx"                    '' 
        Dim fullfilename as string = server.mappath([filename]) '' Get the full local filesystem filename
        Response.Clear()                                        '' We don't want to send any of the current page back
        Response.Headers.Add("Filename", filename)             '' Set the filename 
        HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("attachment;filename={0}.xlsx", filename))  '' This tells the browser that the content is an ATTACHMENT, i.e. to save it, not open it
        Response.ContentType = "vnd.openxmlformats-officedocument.spreadsheetml.sheet"  '' The Content-type for XLSX spreadsheets
        Response.WriteFile(fullfilename)                         '' Send the actual file content
        Response.End()                                           '' End the response - nothing else gets sent





这里的重要部分是 content-disposition ,告诉浏览器下载而不是打开它。浏览器如何处理这是特定于浏览器的; Chrome会始终将其放在下载文件夹中,IE可能会提示您输入位置。希望以上内容对您有所帮助,即使只有一些关键词可以进一步研究。



祝你好运!



The important part here is the content-disposition, which tells the browser to "download" rather than open it. How the browser deals with this is browser-specific; Chrome will always put it in the Downloads folder, IE may prompt you for a location. Hopefully the above will help you, even if only with some keywords to research further.

Good luck!


这篇关于在VB中从Web浏览器下载保存为对话框的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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