DirectoryInfo 访问虚拟文件夹

发布于 2024-09-25 16:24:20 字数 363 浏览 1 评论 0原文

我正在尝试在虚拟目录上使用 DirectoryList 来构建文件列表。但是我收到错误;

不支持 URI

是否有支持 URL 的替代方案?到目前为止,这是我的代码......

DirectoryInfo directoryinfo = new DirectoryInfo("http://localhost:1080/mydatafolder");
IEnumerable<FileInfo> fileList = directoryinfo.GetFiles();

经过仔细检查,我已确保目录浏览已打开,并且我可以使用 Opera 浏览它。

I'm trying to use DirectoryList on a virtual directory, to build up a list of files. However I get the error;

URI not supported

Is there an alternative to this that supports URLs? Here's my code so far.....

DirectoryInfo directoryinfo = new DirectoryInfo("http://localhost:1080/mydatafolder");
IEnumerable<FileInfo> fileList = directoryinfo.GetFiles();

As double check, I've made sure the directory browsing has been turned on, and I can surf to it using Opera.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

耳根太软 2024-10-02 16:24:20

DirectoryInfo 仅适用于文件系统,您应该使用 DirectoryEntry 来获取 IIS 信息。

看看这篇文章,了解获取和获取信息的各种方法。使用c#修改IIS元数据:
http://www.codeproject.com/KB/cs/iismanager.aspx

DirectoryInfo is for the filesystem only, you should use DirectoryEntry to get IIS information.

Have a look at this article to see all kinds of ways to get & modify IIS metadata using c#:
http://www.codeproject.com/KB/cs/iismanager.aspx

荒芜了季节 2024-10-02 16:24:20

如果您想从远程 HTTP 服务器获取文件列表,您可以使用 HttpWebRequest 类用于发布目录列表请求并解析 IIS 返回的 HTML 索引页的内容

这是一个开始:

var request = (HttpWebRequest)WebRequest.Create("http://servername/directoryname/");
var response = (HttpWebResponse)request.GetResponse();

using (var reader = new StreamReader(response.GetResponseStream()))
{
    string body = reader.ReadToEnd();
}

相关资源:

If you want to get a list of files from a remote HTTP server you could use the HttpWebRequest class to post a directory listing request and parse the contents of the HTML index page returned by IIS.

Here's a start:

var request = (HttpWebRequest)WebRequest.Create("http://servername/directoryname/");
var response = (HttpWebResponse)request.GetResponse();

using (var reader = new StreamReader(response.GetResponseStream()))
{
    string body = reader.ReadToEnd();
}

Related resources:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文