App.Path equivalent in VB.Net Windows Service

  • Thread starter Thread starter Jim
  • Start date Start date
J

Jim

I am writing a Windows Service in VB.Net, and right upfront I need to pass
the path to my config.xml file to the constructor of the class which reads
it. In the old days, App.Path & "\config.xml" would have done nicely. I have
tried using Reflection.Assembly.GetExecutingAssembly.Location but this is
horrible! I can't use the easy Application.Path property because it is a
service not a Forms application.

Is there a simple way to do this, or does anyone have any less than simple
but working code which might give me a clue?

Regards

--Jim.
 
Chris said:
Application.StartupPath

----- Original Message -----
From: "Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com>
Newsgroups: microsoft.public.dotnet.languages.vb
Sent: Friday, December 10, 2004 5:48 PM
Subject: Re: App.Path equivalent in VB.Net Windows Service

Application.StartupPath

Application.StartupPath doesn't work for a Service, only a Forms App (I
think, I can't make it go anyway). HOWEVER I have now found the answer:
System.AppDomain.CurrentDomain.BaseDirectory()Regards--Jim.
 
You are right, I read it too quickly... It's one of those days...

Chris
 
Jim said:
I am writing a Windows Service in VB.Net, and right upfront I need to pass
the path to my config.xml file to the constructor of the class which reads
it. In the old days, App.Path & "\config.xml" would have done nicely. I
have tried using Reflection.Assembly.GetExecutingAssembly.Location but this
is horrible! I can't use the easy Application.Path property because it is a
service not a Forms application.

\\\
Imports System.IO
Imports System.Reflection
..
..
..
Private Function ApplicationPath() As String
Return _
Path.GetDirectoryName([Assembly].GetEntryAssembly().Location)
End Function
///

BTW: Use 'System.IO.Path.Combine' to combine paths instead of using '&'.
 
Back
Top