How do I get a directory listing for a folder on the web? I’m looking to download a group of small files from a folder on the web. I can do it easily with a a single file but I’m not sure how to do it for multiple files. If there was something similar to the code below but for a folder on the web I think I can do it.
private void button1_Click(object sender, EventArgs e)
{
DirectoryInfo di = new DirectoryInfo("c:/myFolder");
FileInfo[] rgFiles = di.GetFiles("*.*");
foreach (FileInfo fi in rgFiles)
{
//Do Something with each of them
}
}
The folder is just one from my web site. e.g. mysite.com/files
Thanks
Normal HTTP doesn’t provide any mechanisms for doing this. Even if you had enabled directory browsing on the server and did not specify a default document, all that does is tell the web server to generate a file listing in HTML. You’d have to parse the HTML and it will vary from server to server.
There’s other protocols that sit on top of HTTP like WebDAV that provide this kind of functionality but it’s quite complex. FTP (or UNC share as Jordan mentions) is probably a simpler option if you have control over the server side.