Home All Groups Group Topic Archive Search About

file:// scheme and directories

Author
13 Nov 2006 12:23 AM
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?

Author
13 Nov 2006 12:57 AM
Carl Daniel [VC++ MVP]
wizof***@hotmail.com wrote:
Show quote
> 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/default.asp?url=/library/en-us/cpguide/html/cpconprogrammingpluggableprotocols.asp
for details.

-cd
Author
13 Nov 2006 11:43 AM
wizofaus
Carl Daniel [VC++ MVP] wrote:
Show quote
> wizof***@hotmail.com wrote:
> > 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.
>
The file:// scheme is definitely supported (by means of
FileWebRequest), but it only appears to work with files, not
directories, that was my point.
Author
13 Nov 2006 2:45 PM
Carl Daniel [VC++ MVP]
wizof***@hotmail.com wrote:
Show quote
> Carl Daniel [VC++ MVP] wrote:
>> wizof***@hotmail.com wrote:
>>> 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.
>>
> 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

AddThis Social Bookmark Button