views:

38

answers:

2

I'm trying to use DirectoryList on a virtual directory, to build up a list of files. However I get the error;

URI not supported

Is there an alternative to this that supports URLs? Here's my code so far.....

DirectoryInfo directoryinfo = new DirectoryInfo("http://localhost:1080/mydatafolder");
IEnumerable<FileInfo> fileList = directoryinfo.GetFiles();

As double check, I've made sure the directory browsing has been turned on, and I can surf to it using Opera.

+2  A: 

DirectoryInfo is for the filesystem only, you should use DirectoryEntry to get IIS information.

Have a look at this article to see all kinds of ways to get & modify IIS metadata using c#: http://www.codeproject.com/KB/cs/iismanager.aspx

Chris van de Steeg
A: 

If you want to get a list of files from a remote HTTP server you could use the HttpWebRequest class to post a directory listing request and parse the contents of the HTML index page returned by IIS.

Here's a start:

var request = (HttpWebRequest)WebRequest.Create("http://servername/directoryname/");
var response = (HttpWebResponse)request.GetResponse();

using (var reader = new StreamReader(response.GetResponseStream()))
{
    string body = reader.ReadToEnd();
}

Related resources:

Enrico Campidoglio
Thanks for the answer, quite illuminating. Appreciated!
wonea