Getting list of files in directory from a web site

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Does anyone know how to get a list of files for a given directory from a
given url.
I have the following, but get an error indicating that URI formats are not
supported.

System.IO.DirectoryInfo di
di = new System.IO.DirectoryInfo("http://www.websitehere.com/files/");
System.IO.FileInfo[] rgFiles = di.GetFiles("*.jpg");
foreach(System.IO.FileInfo fi in rgFiles)
{
MessageBox.Show (fi.Name);
}

Is there a way of doing this without ftp?
 
The web site must allow directoy browsing, and the result you get back from
requesting a dir with no default directoy could be parsed. If it has a
default page set you cant list the dir contents. This is how web servers
work by design.

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP
 
Opa,

No what you ask is typical FTP and than the directory has to be on a FTP
server (and be configured there as an ftp directory).

For HTTP this should normally absolute be impossible and therefore made
every day more impossible.

I hope this helps a little bit.

Cor
 
Hi Cor,
For HTTP this should normally absolute be impossible and therefore made
every day more impossible.

If directory browsing is turned on for the site, then this works just fine.
If you look at the RFC for HTTP 1.1, you will see that directory browsing is
a normal and supported use of HTTP. In fact, it was the original use.
Default pages were a later invention.

http://www.w3.org/Protocols/rfc2068/rfc2068

By the way, there is nothing wrong with doing this if all your pages are
simple text or HTML. There are many tens of thousands of older web sites
that still operate this way. This is not a security risk if the site
contains only text (and some still do).

--- Nick
 
Hi Nick,

Can you show me a sample how to do that getting a "List of files in a
directory from a website" with HTTP 1.1

I am as well very interested in that

Cor
 
Sure Cor,

1) open any web site on your web server or create a new one. put a text or
simple HTML file in it. I called mine "mynewsite"
2) open the properties for that site in IIS manager. Check "allow directory
browsing". click OK
3) using IE, hit your site, but don't specify any file name.
http://localhost/mynewsite

you will get a list of the files in the site with a link under each
filename. click the link to open the page.

I'm on Windows 2000 here (I'm at home... I have XP and WS2003 at work). I
set this up in about 2 minutes.

--- Nick
 
Did anyone ever answer your question?

Use HTTPWebClient. I don't know if you can use the URI of .../files/*.jpg
or if you have to just say .../files/* and then look for the JPG files.

Note: this will only work if the web server has directory browsing turned on
for this site.

I don't know if you get the same HTTP response with different web servers.
I would suspect that you do, but I haven't dug far enough into the W3C RFCs
to see if there's a standard for returning the file list.

--- Nick
 
Nick,

I did not know this, however doing it I saw there should as well not be a
default page in that folder.

(Just for the thread)

Thanks,

Cor
 
Back
Top