简体   繁体   中英

How to Get Files From A Directory That's Open for Directory Listing?

Assume that a website has set the directory listing permissions open for one of its folder and I can see files on the web browser[as on the image]. Is there a way to get files in this folder to an array?

在此处输入图片说明

In a word, I need to use a method that's doing what DirectoryInfo.GetFiles("C:/"); for an URL.

Edit: I'd rather want to use a method instead of getting web response and parse the result. That's like a back door in case there's not an alternative way.

This code will help you get the html

             WebRequest request = WebRequest.Create("http://yourwebsite/yourwebdirectory/");
             var webResponse=request.GetResponse();
             Stream dataStream = webResponse.GetResponseStream(); 
             StreamReader reader = new StreamReader(dataStream); 
             string responseFromServer = reader.ReadToEnd(); 
             Console.WriteLine(responseFromServer); 
             reader.Close();
             webResponse.Close();

Once you get the html you can parse it to get the file names

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