C# 通过 Web 服务访问文件夹/文件
如何让网络服务读取/浏览文件夹内容?
例如这种类型的代码:
FolderBrowserDialog folderBrowser;
folderBrowser = new System.Windows.Forms.FolderBrowserDialog();
folderBrowser.Description = "...";
folderBrowser.ShowNewFolderButton = false;
folderBrowser.RootFolder = Environment.SpecialFolder.MyComputer;
当我构建解决方案时,我收到此错误...
类型或命名空间名称 “FolderBrowserDialog”不能 找到了(您是否缺少使用 指令还是程序集引用?)
我知道尝试在 Web 服务中使用对话框没有多大意义,但我还能怎么做呢?
我的网络服务收到一个字符串,然后我想浏览文件夹中包含该字符串的文件。
How can I have a webservice read/browse a folder content ?
For instance this type of code:
FolderBrowserDialog folderBrowser;
folderBrowser = new System.Windows.Forms.FolderBrowserDialog();
folderBrowser.Description = "...";
folderBrowser.ShowNewFolderButton = false;
folderBrowser.RootFolder = Environment.SpecialFolder.MyComputer;
When I build the solution I get this error...
The type or namespace name
'FolderBrowserDialog' could not be
found (are you missing a using
directive or an assembly reference?)
I know it doesn't make a lot of sense trying to use a dialog in a webservice but how else can I do it?
My webservice receives a string and then I want to browse for files that contain that string in a folder.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要使用 System.IO 命名空间来导航到您的文件系统;正如您所指出的,尝试在 Web 服务调用上显示对话框是没有意义的。
You'll need to use
System.IO
namespace to navigate into your filesystem; as you noted, doesn't make sense trying to display a dialog on a webservice call.查看 System.IO.Directory.GetFiles() 方法。显示FolderBrowser 对话框自然只能与胖客户端交互式WinForms 应用程序一起使用。
Have a look at the
System.IO.Directory.GetFiles()
method. Displaying the FolderBrowser dialog can naturally only be used with thick client interactive WinForms apps.使用 StreamReader 读取文本文件:
列出文件夹中的文件:
Use a StreamReader to read a text file:
To list files in a folder: