By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,417 Members | 835 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,417 IT Pros & Developers. It's quick & easy.

Generic path description - please help

P: n/a
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.

Mar 28 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi,

http://www.vb-tips.com/default.aspx?...c-dfa89d0d9842

Ken
------------
<al*****@altavista.com> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com...
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.

Mar 28 '06 #2

P: n/a
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

Mar 28 '06 #3

P: n/a
"Ken Tucker [MVP]" <vb***@bellsouth.net> schrieb:
http://www.vb-tips.com/default.aspx?...c-dfa89d0d9842


In addition to that, you may want to use 'GetExecutingAssembly' instead of
'GetEntryAssembly' in order to get the path to the DLL containing the call
to the method.

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

Mar 28 '06 #4

P: n/a
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

Mar 29 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.