|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
URI IsFileHi 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 Your URI is without a doubt an FTP URI, not a File URI!to | me as that is without a doubt an URI to a file... 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) What do you mean by "a file"?| Are there any other ways of detecting if this is a file reliably? -- Show quoteHide quoteHope 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$HfJgHkGHA.5020@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. | | 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? i.e. not just a path like> What do you mean by "a file"? 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.
Show quote
Hide quote
"NickP" <a@a.com> schrieb: Hm... The trailing backslash indicates that the directory's default >> | 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. 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/> | MsgBox(New Yes one could, however if you are checking IsFile in a number of places, | Uri("ftp://pop.com/pop.bmp").Scheme.Equals(Uri.UriSchemeFile)) << false 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/ -- Show quoteHide quoteHope 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:eD31SAJkGHA.3484@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. | | "NickP" <a@a.com> schrieb: Yes! Did you read the documentation for 'Uri.IsFile'? 'IsFile' returns > The following returns "False"... > > MsgBox(New Uri("ftp://me.pop.com/pop.bmp").IsFile.ToString) > > Is there any particular reason? '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/> Hi Herfried,
> Yes! Did you read the documentation for 'Uri.IsFile'? 'IsFile' returns Yeah it just didn't seem to make sense if you could perform the check > 'True' if the URI's scheme is "file" ('Uri.UriSchemeFile'). 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 Nick.> of resource it is referring to. :-( Oh well, thanks for the help anyway.
Streaming a file to text?
How to force upper case in a DataGridView column? Dealing with NULL values in Integer fields Mulples threads and impersonation Calling a batch file from vb.net with parameters Handle pointers from delphi client to a vb.net dll What's the Best Startup Scenario for Unattended Server Execution? VB.net 2005 splash screen "Optional ByVal SomeDate As Date = Nothing" in VB2005 writing a text in a file in vb.net not working properly |
|||||||||||||||||||||||