file:// scheme and directories

  • Thread starter Thread starter wizofaus
  • Start date Start date
W

wizofaus

Under firefox, if you enter in the URL

file://c:/

You'll get an HTML-ized version of the C:/ directory. Under IE, it
actually redirects to a regular Explorer window showing your c:\
folder.

But if you try to use .NET WebRequest.Create("file://c:/"), at least
with .NET 1.1, you get an "Access to the path "c:\" is denied" error,
which seems a bit rude. There's actually nothing in the documentation
that says if you're using the file:// scheme you can't reference a
directory, but obviously it's not designed to work. Is this any
different in .NET 2.0, and if not, is there any likelihood of it
changing in the future?
 
Under firefox, if you enter in the URL

file://c:/

You'll get an HTML-ized version of the C:/ directory. Under IE, it
actually redirects to a regular Explorer window showing your c:\
folder.

But if you try to use .NET WebRequest.Create("file://c:/"), at least
with .NET 1.1, you get an "Access to the path "c:\" is denied" error,
which seems a bit rude. There's actually nothing in the documentation
that says if you're using the file:// scheme you can't reference a
directory, but obviously it's not designed to work. Is this any
different in .NET 2.0, and if not, is there any likelihood of it
changing in the future?

Note that the name of the class in .NET is HttpWebRequest - it only serves
the Http scheme, and I wouldn't expect that to change.

You could derive your own FileWebRequest class and register the file: scheme
with the WebRequest class. See
http://msdn.microsoft.com/library/d...e/html/cpconprogrammingpluggableprotocols.asp
for details.

-cd
 
Carl said:
Note that the name of the class in .NET is HttpWebRequest - it only serves
the Http scheme, and I wouldn't expect that to change.
The file:// scheme is definitely supported (by means of
FileWebRequest), but it only appears to work with files, not
directories, that was my point.
 
The file:// scheme is definitely supported (by means of
FileWebRequest), but it only appears to work with files, not
directories, that was my point.

Ah, I missed that detail. What would you have it return in the response if
you requested a directory? The browsers you mention are fabricating a
document in some unspecified format and returning that, or popping up an
entirely different type of window - neither of which falls within the
purview of a web request.

You could implement your own FileWebRequest class that fabricates some kind
of document when you request a directory, but strictly speaking, a web
request fetches a document, and a directory is not naturally a document that
can be returned.

-cd
 
Back
Top