473,396 Members | 1,923 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Generic path description - please help

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
4 920
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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Michael Kennedy [UB] | last post by:
Hi Everyone, I have this multithreaded C# windows forms application which does a lot of image processing. Occasionally, I get the following error: A generic error occurred in GDI+....
8
by: Glenn A. Harlan | last post by:
Why am I receiving the below error when calling - Path.GetTempFileName() The directory name is invalid. Description: An unhandled exception occurred during the execution of the current web...
15
by: (Pete Cresswell) | last post by:
I've got a .BAT file that I use for executing various MS Access apps that I wrote way back in the days of 2.0. It's evolved over time, but it still contains a number of possible paths to...
2
by: Alphonse Giambrone | last post by:
I am currently reading 'Programming The Web with Visual Basic .NET' and have so far found it to be excellent. Downloaded all the code from Apress and working in chapter 4, I get the error shown...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
3
by: bobdydd | last post by:
Hi Everybody Access 2000, Outlook 2000 Windows XP I am running the code below to open Microsoft Outlook from a Command Button. It works fine until I tried it on a machine that has Office...
0
by: crazyone | last post by:
I've got a gaming framework i'm building and i want to save myself the trouble of reading and writting the complete game data to a custom file and load/save it to an XML file but i'm getting...
18
by: NDayave | last post by:
ive managed to piece together this code that creates a backup folder and then copies the (Access 2000) database into it under the new name "Backup YYYY-MMM-DD HH.MM". It worked fine in the...
0
by: sachinrohamare | last post by:
I am getting following error while iterating through the ManagementObjectCollection: This error is coming only for the first time. From the 2nd run onwards the code is executed successfully....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.