简体   繁体   中英

how to get directory files name from web

i want to read web directory files. when i use this code.

string[] files;
string webfilepath = "http://www.anydomain.com/templates/images";
files = Directory.GetFiles(webfilepath, @"*.*", SearchOption.TopDirectoryOnly);

code shows error url format not support.is there any other way to read web directory. thanks in advance.

is there any other way to read web directory

No. HTTP has no "directory index" you can retrieve, unless the server (or software running on it) generates it itself, for example Apache's Options +Indexes configuration. But then that index is generated in HTML, which you'll have to parse to get the full filename.

You are trying to pass url to Directory.GetFiles instead of passing physical path of folder, You can use Server.MapPath to get the physical path of url if it is accessible ie the code for accessing folder is running on the machine url is point to. If url is on different machine then you can not use Directory.GetFiles .

you cant do this in a generic way. Because its up to the web server how it dump the directory content on to client if it does that at all.

First you need to make sure that your server send out the content using some protocol. then you can use HttpWebRequest to send a HTTP request and get the result. you will have to do your own parsing on the result at the end of the day.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM