|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Generic path description - please helpHi,
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. Hi,
http://www.vb-tips.com/default.aspx?ID=73bbbf0d-1876-4d18-b55c-dfa89d0d9842 Ken ------------ <almu***@altavista.com> wrote in message Show quoteHide quote news:1143545405.051824.277070@v46g2000cwv.googlegroups.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. > 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: : Regards,End Try ------------------------------------------ HTH, Cerebrus "Ken Tucker [MVP]" <vb***@bellsouth.net> schrieb: In addition to that, you may want to use 'GetExecutingAssembly' instead of > http://www.vb-tips.com/default.aspx?ID=73bbbf0d-1876-4d18-b55c-dfa89d0d9842 '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/> 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
Derived TextBox
adding items to a listbox that are null problem Folder size in VB.NET? Financial.Rate Cannot calculate rate using the arguments provided which is better Problem with - Edit Item of Collections.Generic.List(Of SearchAreaListItem) Shell to DOS Abstract/Base Class Best Practices - Help How to read S.M.A.R.T. attributes in vb ? Instance of derived class does not show public methods or properties that are not in the inherited c |
|||||||||||||||||||||||