471,082 Members | 706 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,082 software developers and data experts.

URI IsFile

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.
Jun 15 '06 #1
6 3159
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/lib...me(VS.80).aspx

http://msdn2.microsoft.com/en-us/lib...le(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
"NickP" <a@a.com> wrote in message
news:O$**************@TK2MSFTNGP02.phx.gbl...
| 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.
|
|
Jun 15 '06 #2
"NickP" <a@a.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jun 15 '06 #3
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.
Jun 15 '06 #4
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.
Jun 15 '06 #5
"NickP" <a@a.com> schrieb:
| 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.


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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jun 15 '06 #6
| 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
"NickP" <a@a.com> wrote in message
news:eD**************@TK2MSFTNGP03.phx.gbl...
| 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.
|
|
Jun 15 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Gonnasi | last post: by
1 post views Thread by Flix | last post: by
7 posts views Thread by C. A. Kelly | last post: by
1 post views Thread by Gary Wessle | last post: by
5 posts views Thread by 7stud | last post: by
10 posts views Thread by ppaterson | last post: by
2 posts views Thread by 7stud | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.