我正在开发一个Web应用程序,其中一个页面有一些必要性,用户应该选择系统中的任何文件夹,例如如果他选择ex:D:\xyz,那么这个路径应该保存在数据库中,我已经编写了代码用于存储到数据库并保留所有内容。但实际上我认为,如果它就像一个浏览按钮单击功能来选择文件夹,我所做的是,因为我不知道如何在 Web 应用程序中制作它,我只是使用一个文本框来让用户能够输入路径。有人可以帮助我如何在网页中应用“打开文件对话框”功能吗?
预先感谢,
问候
卡延。
I am devoloping a Web Application, in which one Page has some neccessity that User should select any folder in the System and for ex if he selects ex:D:\xyz, then this Path should be Saved in Database, I have written the Code for Storing in to Database and Remaining Every thing. But actually i think that if it is like a Browse Button click function to select the Folder, what i have made is, as i dont know how to make it in Web Application simply i used a textbox to be able to user to type the Path. Can, any one help me how to apply the Open File Dialog Functionality in a Web Page?
Thanks in Advance,
Regards
Kalyan.
发布评论
评论(4)
没有 ASP.Net 控件来选择文件夹。
作为一个简单的解决方法,您可以使用 FileUpload - 控件让用户选择一个文件,您可以 保存该文件的文件夹。但这仅适用于 IE,因为其他浏览器不会发布完整的文件路径,而只会发布文件名(安全限制)。
编辑:正如 Ben 提到的,这在 IE>7 中也不起作用:
http:// /blogs.msdn.com/b/ie/archive/2008/07/02/ie8-security-part-v-compressive-protection.aspx(
文件上传控制
部分)There is no ASP.Net Control to select folders.
As a simple workaround you could use the FileUpload-Control to let the user select a file and you can save the folder of that file. But that would work only in IE because other browsers don't post the full file-path but only the file-name(security restrictions).
Edit: As Ben mentioned that doesn't work in IE>7 either:
http://blogs.msdn.com/b/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx (section
File Upload Control
)对于网络应用程序:
For Web Application:
通过右键单击解决方案浏览项目名称添加引用 system.windows.forms,将 Windows 打开文件对话框引用添加到 Web 应用程序
然后按照这里的编码风格,我已经给出了
VB
示例代码,如果您遇到任何问题告诉我,您可以将其转换为C#
。VB代码
Add windows openfile dialog reference toweb application by righ click on solution explore project name add reference system.windows.forms
then follow this coding style here i have given
VB
sample code you can convert this toC#
if your facing any problem tell me.VB Code
如果您想要服务器文件或文件夹的路径,则必须让服务器提供可供选择的可能文件夹的列表。
如果您只需要本地文件的路径,则无法从 Web 应用程序执行此操作。
最简单的解决方案是告诉用户在资源管理器中浏览并复制路径,以粘贴到对话框中。
If you want the path of a server file or folder, you have to get the server to give a list of possible folders to choose from.
If you just want the path of a local file, you cannot do this from a web application.
The easiest solution is to tell the user to browse in Explorer and copy the path, to paste in your dialog.