469,610 Members | 1,862 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,610 developers. It's quick & easy.

App.Path equivalent in VB.Net Windows Service

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.
Nov 21 '05 #1
4 16578
Application.StartupPath
"Jim" <no******@this.address> wrote in message
news:Bg****************@fe2.news.blueyonder.co.uk. ..
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.

Nov 21 '05 #2
Jim

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:eV**************@TK2MSFTNGP12.phx.gbl...
Application.StartupPath
"Jim" <no******@this.address> wrote in message
news:Bg****************@fe2.news.blueyonder.co.uk. ..
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.

----- 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
"Jim" <no******@this.address> wrote in message
news:Bg****************@fe2.news.blueyonder.co.uk. ..
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.



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()Rega rds--Jim.
Nov 21 '05 #3
You are right, I read it too quickly... It's one of those days...

Chris
"Jim" <no******@this.address> wrote in message
news:l_*****************@fe2.news.blueyonder.co.uk ...

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com>
wrote in message news:eV**************@TK2MSFTNGP12.phx.gbl...
Application.StartupPath
"Jim" <no******@this.address> wrote in message
news:Bg****************@fe2.news.blueyonder.co.uk. ..
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.Locati on 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.


----- 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
"Jim" <no******@this.address> wrote in message
news:Bg****************@fe2.news.blueyonder.co.uk. ..
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.Locati on 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.



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()Rega rds--Jim.

Nov 21 '05 #4
"Jim" <no******@this.address> schrieb:
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 '&'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Laszlo Zsolt Nagy | last post: by
14 posts views Thread by Gianfranco | last post: by
1 post views Thread by Jody Gelowitz | last post: by
3 posts views Thread by Vikas Kumar | last post: by
2 posts views Thread by Gregor Horvath | last post: by
12 posts views Thread by Anil Gupte | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.