使用 ASP.NET,如何通过同一个对话框选择多个文件
我正在尝试从 ASP.NET 页面将一些文件上传到 ftp 服务器。一切都准备好了,但是我想使用打开的文件对话框来选择我要上传的文件。如何启用文件上传来选择多个文件,如果不能,我可以像普通 Windows 窗体应用程序一样使用 OpenFileDialog 吗?
提前致谢
I'm trying to upload some files to an ftp server from an ASP.NET page. Everything is ready however I would like to use an open file dialog to select the files I want to upload. How can I enable file upload to select multiple files, and if I can't, can I simply use the OpenFileDialog like a normal windows forms application ?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
问题在于,在 Web 应用程序的上下文中,您将数据作为 KeyValuePair 发布。因此,单个
元素只能包含一个文件,因为它只是一个键。
OpenFileDialog
将在服务器端的窗口中执行;客户永远不会看到它。您的选择是要么限制为 1 个文件(并有一个按钮来添加另一个文件上传),要么转向类似 Gmail 的方法,在该方法中您使用 Flash/插件来获得该功能。
The issue is that in the context of a web application, you post data as a KeyValuePair. So a single
<input type="file" name="Something" />
element can contain only one file because it is only one key.An
OpenFileDialog
would be executed server side in a window there; the client would never see it.Your options are to either limit to 1 file (and have a button to add another file upload), or move to a gmail like approach where you use a flash / plugin to get that functionality.
标准的 HTML 浏览对话框不会让你这么做。但是,官方 ASP.NET 网站上有一个名为 ASP.NET 2 中的多文件上传,您应该看看。 此处有一些基于此的代码。
通常,您会使用基于 Flash 或 JavaScript/AJAX 的解决方案。有很多可用的控件可以做到这一点,例如。
只需谷歌“多文件上传”即可了解更多信息。
The standard HTML browse dialogue won't let you. However, there's a video on the official ASP.NET site called Multiple File Uploads in ASP.NET 2 that you should look at. There's some code based on that here.
Generally you would either use a Flash or JavaScript/AJAX based solution. There are plenty of controls available that can do this eg.
Just google 'multiple file upload' for far more.
将 OpenFileDialog 的
MultiSelect
属性设置为 true。Set OpenFileDialog's
MultiSelect
property to true.您可能想查看这些帖子:
如何选择多个文件进行上传?
在网页中选择多个文件上传
You may want to look at these SO posts:
How to select multiple files for upload?
Selecting Multiple Files for Upload in Web Page
看看这里如何上传多个文件。您有多个 FileUpload 控件并使用 HttpFileCollection 来获取文件。
http://www.dotnetcurry.com/ShowArticle.aspx?ID=68& ;AspxAutoDetectCookieSupport=1
Have a look here on how to upload multiple files. You have multiple FileUpload controls and use HttpFileCollection to get the files.
http://www.dotnetcurry.com/ShowArticle.aspx?ID=68&AspxAutoDetectCookieSupport=1
我也研究了这一点,但没有办法在一个文件控件中选择多个文件,因为文件控件的限制是一次只能选择一个文件
所以您将采取多个文件控制来导入多个文件
i also research on this point but there is no a way to select a multiple file at one file control beacuuse the limitation of the file controll is select only one file at the time
so you will take multiple file control for import multiple file