0

我想通过http://使用 C# 从一个 web 目录中获取所有文件名和目录列表。

例如:

Directory.GetFiles(folder)**

用于从本地目录获取文件列表,就像我想从 web 目录获取文件列表一样。

4

4 回答 4

5
System.IO.Directory.GetFiles(HttpContext.Current.Server.MapPath("~/PortalPage/"))
于 2013-04-12T07:29:25.733 回答
4

Well, I don't believe HTTP has a "directory index" you can directly use.

You can't pass url to Directory.GetFiles method, this method takes as a parameter physical path of url (if it is accessible of course).

Check out Server.MapPath method instead.

The MapPath method maps the specified relative or virtual path to the corresponding physical directory on the server.

Path

Specifies the relative or virtual path to map to a physical directory. If Path starts with either a forward (/) or backward slash (), the MapPath method returns a path as if Path were a full, virtual path. If Path doesn't start with a slash, the MapPath method returns a path relative to the directory of the .asp file being processed.

于 2013-04-12T07:10:07.383 回答
1

HTTP 本身没有任何功能来列出文件夹中的 FILE 内容。一方面,这是不可能的,因为 HTTP 规范不要求将 URL 映射到文件夹。可编程网页的整个基础是基于未映射到静态文件的 URL。

然而。HTTP 协议有很多扩展。WebDAV 是一种将 HTTP URI 映射到某个位置的目录的协议。在此处查看如何查询 WebDAV 服务以获取文件夹的内容

但是,据我所知,它不能进行递归查询。

于 2013-04-12T07:26:24.823 回答
0

You can't use Directory.GetFiles on a URL.

Consider the example:

string baseURL = "http://download.example.org/export/dump/";
WebClient client = new WebClient();            
string content = client.DownloadString(baseURL);

Then you run a loop inside.

于 2013-04-12T07:08:21.490 回答