Generic path description - please help

A

almurph

Hi,

I have a VB.NET class library and I have to access a xml file that
will always be in the same directory as the class library.

So I use the followign code to open the file:

Dim doc as XmlDocument
doc.Load("C:\folderA\folderB\a.xml")

Thing is though this path is subject to change. Is there any generic
way to say that a.xml will always be in the same folder as this? Do
you know what I mean?

Any comments/suggestions/code-samples much appreciated.

Al.
 
C

Cerebrus

Hi,

Ken's solution is very robust and foolproof, but if High security is
not your priority, you can also use relative paths, like :

Since the xml file is in the same directory as the class library,
------------------------------------------
doc.Load("a.xml")
------------------------------------------

However this has many disadvantages from the Canonicalization point of
view. So to make it more robust, we can use :
------------------------------------------
Dim myXmlPath as string = "a.xml"
Try
Dim exactPath as string = System.IO.Path.GetFullPath(myXmlPath)
doc.Load(exactPath)
:
:
Catch ex as Exception
:
End Try
------------------------------------------
HTH,

Regards,

Cerebrus
 
A

almurph

Thanks everyone - problem is though I keep on getting the wrong
directory. Depending on what technique is use I either get:

C:\windows

or

C:\windoiws\microsoft.net\framework\v1.4322\etc...


Confused,
Al
 

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