[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Online or local path?

Posted on 2006-05-27
11
Medium Priority
?
232 Views
Last Modified: 2008-01-09
Hi there!,
what is the best way to check if a path refeers to a file on your pc or if it is online?


I already made:
if(Directory.Exists(zipPath.Substring(0, zipPath.LastIndexOfAny(new char[]{'\\','/'}))))

because Directory.Exists only works for local files (i gess), but I think this is not very clean.
Any better ideas?
0
Comment
Question by:dkloeck
  • 6
  • 4
11 Comments
 
LVL 11

Expert Comment

by:anyoneis
ID: 16777670
Directory.Exists will access network files - so that won't work reliably for you. Here is a nice little routine: http://vbnet.mvps.org/index.html?code/fileapi/pathislocalpath.htm

David
0
 
LVL 5

Accepted Solution

by:
eltic earned 2000 total points
ID: 16779170
Try using the Uri-class:

Uri u = new Uri(@"c:\test.txt");
if (u.IsLoopback)
{
     Console.WriteLine("File is local file");
}
else
{
     Console.WriteLine("File is remote file");
}
0
 
LVL 10

Author Comment

by:dkloeck
ID: 16783390
hmmm.. don't work after all, it always gives "File is remote file" back
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 10

Author Comment

by:dkloeck
ID: 16783465
btw, my way works fine. From msdn:"The Exists method does not perform network authentication. If you query an existing network share without being pre-authenticated, the Exists method will return false. "
0
 
LVL 5

Expert Comment

by:eltic
ID: 16784441
Give us your test-path, which should be local.
0
 
LVL 10

Author Comment

by:dkloeck
ID: 16784882
local would be everything on your pc like "c:\\test.txt" "\\asdas.bmp" "j:\\test\\test2\\asdfg.txt\\" or whatever on your pc
remote is everything else
0
 
LVL 5

Expert Comment

by:eltic
ID: 16787860
That's clear, but what is the EXACT path you've tested, which is returned as remote file, although it is locally ?
0
 
LVL 10

Author Comment

by:dkloeck
ID: 16789364
hmm.. i gess it was "f:\\Software\\Visual Studio Projects\\Worldwind\\Shapefiles\\AOI.zip"
0
 
LVL 10

Author Comment

by:dkloeck
ID: 16789369
f is one of my hard discs by the way
0
 
LVL 5

Expert Comment

by:eltic
ID: 16789655
What version of the .NET Framework do you use ?
I tried the path above with 2.0 and I get "File is local file".
0
 
LVL 10

Author Comment

by:dkloeck
ID: 16799389
I use VS 2003
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month20 days, 14 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question