URI IsFile

  • Thread starter Thread starter NickP
  • Start date Start date
N

NickP

Hi there,

The following returns "False"...

MsgBox(New Uri("ftp://me.pop.com/pop.bmp").IsFile.ToString)

Is there any particular reason? It seems like a pretty poor function to
me as that is without a doubt an URI to a file...

Are there any other ways of detecting if this is a file reliably?

Thanks in advance.

Nick.
 
Nick,
| Is there any particular reason? It seems like a pretty poor function
to
| me as that is without a doubt an URI to a file...
Your URI is without a doubt an FTP URI, not a File URI!

A file URI uses the "file" scheme, your uri is using the "ftp" scheme.

http://msdn2.microsoft.com/en-us/library/system.uri.scheme(VS.80).aspx

http://msdn2.microsoft.com/en-us/library/system.uri.isfile(VS.80).aspx

Try:

| MsgBox(New Uri("file://me.pop.com/pop.bmp").IsFile.ToString)


| Are there any other ways of detecting if this is a file reliably?
What do you mean by "a file"?

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Hi there,
|
| The following returns "False"...
|
| MsgBox(New Uri("ftp://me.pop.com/pop.bmp").IsFile.ToString)
|
| Is there any particular reason? It seems like a pretty poor function
to
| me as that is without a doubt an URI to a file...
|
| Are there any other ways of detecting if this is a file reliably?
|
| Thanks in advance.
|
| Nick.
|
|
 
NickP said:
The following returns "False"...

MsgBox(New Uri("ftp://me.pop.com/pop.bmp").IsFile.ToString)

Is there any particular reason?

Yes! Did you read the documentation for 'Uri.IsFile'? 'IsFile' returns
'True' if the URI's scheme is "file" ('Uri.UriSchemeFile').
Are there any other ways of detecting if this is a file reliably?

Not really, because an URI doesn't contain any information about the type of
resource it is referring to.
 
Hi Jay,
A file URI uses the "file" scheme, your uri is using the "ftp" scheme.

Hmm, that just seems like a waste of a function to be honest. If all it
is doing is checking for a "file://" protocol then that feature is already
available via.

MsgBox(New
Uri("ftp://pop.com/pop.bmp").Scheme.Equals(Uri.UriSchemeFile)) << false
MsgBox(New
Uri("file://pop.com/pop.bmp").Scheme.Equals(Uri.UriSchemeFile)) << true
| Are there any other ways of detecting if this is a file reliably?
What do you mean by "a file"?

i.e. not just a path like

http://www.mysite.com/pop/
http://www.mysite.com/pop/pants/
http://www.mysite.com/pop/pants/foobar/

more like

http://www.mysite.com/pop/pants/myfile.html
http://www.mysite.com/pop/pants/football/myfile2.html

I've resorted to checking for a trailing backslash on the absolute path.
If it's not then it's presumed to be a file. Although this is not ideal it
is working for what I currently want it for.

Cheers for clearing that up for me anyway.

Nick.
 
Hi Herfried,
Yes! Did you read the documentation for 'Uri.IsFile'? 'IsFile' returns
'True' if the URI's scheme is "file" ('Uri.UriSchemeFile').

Yeah it just didn't seem to make sense if you could perform the check
manually anyway...

MsgBox(New
Uri("ftp://pop.com/pop.bmp").Scheme.Equals(Uri.UriSchemeFile)) << false
MsgBox(New
Uri("file://pop.com/pop.bmp").Scheme.Equals(Uri.UriSchemeFile)) << true
Not really, because an URI doesn't contain any information about the type
of resource it is referring to.

:-( Oh well, thanks for the help anyway.

Nick.
 
NickP said:
i.e. not just a path like

http://www.mysite.com/pop/
http://www.mysite.com/pop/pants/
http://www.mysite.com/pop/pants/foobar/

more like

http://www.mysite.com/pop/pants/myfile.html
http://www.mysite.com/pop/pants/football/myfile2.html

I've resorted to checking for a trailing backslash on the absolute
path. If it's not then it's presumed to be a file. Although this is not
ideal it is working for what I currently want it for.

Hm... The trailing backslash indicates that the directory's default
document (which is often a file) should be returned, at least for common
HTTP servers.
 
| MsgBox(New
| Uri("ftp://pop.com/pop.bmp").Scheme.Equals(Uri.UriSchemeFile)) << false
Yes one could, however if you are checking IsFile in a number of places,
that is a lot of duplicated code.

Further IsFile feels like an attribute of Uri, while UriSchemeFile feels
more like an implementation detail.


To understand the smell of duplicated code see Refactoring by Martin Fowler:

http://martinfowler.com/books.html#refactoring

http://www.refactoring.com/


--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Hi Jay,
|
| > A file URI uses the "file" scheme, your uri is using the "ftp" scheme.
|
| Hmm, that just seems like a waste of a function to be honest. If all
it
| is doing is checking for a "file://" protocol then that feature is already
| available via.
|
| MsgBox(New
| Uri("ftp://pop.com/pop.bmp").Scheme.Equals(Uri.UriSchemeFile)) << false
| MsgBox(New
| Uri("file://pop.com/pop.bmp").Scheme.Equals(Uri.UriSchemeFile)) << true
|
| > | Are there any other ways of detecting if this is a file reliably?
| > What do you mean by "a file"?
|
| i.e. not just a path like
|
| http://www.mysite.com/pop/
| http://www.mysite.com/pop/pants/
| http://www.mysite.com/pop/pants/foobar/
|
| more like
|
| http://www.mysite.com/pop/pants/myfile.html
| http://www.mysite.com/pop/pants/football/myfile2.html
|
| I've resorted to checking for a trailing backslash on the absolute
path.
| If it's not then it's presumed to be a file. Although this is not ideal
it
| is working for what I currently want it for.
|
| Cheers for clearing that up for me anyway.
|
| Nick.
|
|
 
Back
Top