File.Exists() and URI?

  • Thread starter Gustaf Liljegren
  • Start date
G

Gustaf Liljegren

I have a document with links written in the URI syntax, like this:

file:///c:/folder/example1.xml
file:///c:/folder/example2.xml

I want to check if these file exists before I read them, but the
IO.File.Exists() method doesn't seem to handle the URI syntax. Is there an
alternative way for URIs, or do I need to parse the URIs and write them as
Windows file paths?

Thanks,

Gustaf
 
N

Nicholas Paldino [.NET/C# MVP]

Gustaf,

You can pass the URL to the Uri class constructor. Once you have an Uri
instance, you can get the filename using the LocalPath property, which
returns the local operating-system representation of a filename.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top