471,349 Members | 1,217 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Windows Service startup path for settings

Hi!

I have made quite simple Windows Service using C# 2005. I also made
Setup for it into same solution. When I run Setup, it will be installed
ok into C:\Program Files\<MyCompany>\<MyService>.

Setup is also installing self made default "settings.xml"-file into the
same directory. It contains DataTable for the service how to work, that
service is reading into DataTable-object when it is started. These
settings are not same as <MyService>.exe.config settings.

Now the problem is that Service is trying to find this
"settings.xml"-file of the C:\WINDOWS\System32 instead of C:\Program
Files\<MyCompany>\<MyService-path, when my "settingsHandler"-class
contains declaration...

private const string FILE_PATH = "settings.xml";

....and execution fails. How can I tell to the service it should find
this file of the "Application.StartupPath" ?
--
thanks in advance!

Mika
Aug 7 '08 #1
5 7979
"Mika M" <mi*********************@gmail.comwrote in message
news:Oh****************@TK2MSFTNGP02.phx.gbl...
Hi!

I have made quite simple Windows Service using C# 2005. I also made Setup
for it into same solution. When I run Setup, it will be installed ok into
C:\Program Files\<MyCompany>\<MyService>.

Setup is also installing self made default "settings.xml"-file into the
same directory. It contains DataTable for the service how to work, that
service is reading into DataTable-object when it is started. These
settings are not same as <MyService>.exe.config settings.

Now the problem is that Service is trying to find this "settings.xml"-file
of the C:\WINDOWS\System32 instead of C:\Program
Files\<MyCompany>\<MyService-path, when my "settingsHandler"-class
contains declaration...

private const string FILE_PATH = "settings.xml";
private const string FILE_PATH =
System.AppDomain.CurrentDomain.BaseDirectory +
"settings.xml";

Aug 7 '08 #2
On Aug 7, 9:08*am, Mika M <mika.mahonen_removet...@gmail.comwrote:
Hi!

I have made quite simple Windows Service using C# 2005. I also made
Setup for it into same solution. When I run Setup, it will be installed
ok into C:\Program Files\<MyCompany>\<MyService>.

Setup is also installing self made default "settings.xml"-file into the
same directory. It contains DataTable for the service how to work, that
service is reading into DataTable-object when it is started. These
settings are not same as <MyService>.exe.config settings.

Now the problem is that Service is trying to find this
"settings.xml"-file of the C:\WINDOWS\System32 instead of C:\Program
Files\<MyCompany>\<MyService-path, when my "settingsHandler"-class
contains declaration...

private const string FILE_PATH = "settings.xml";

...and execution fails. How can I tell to the service it should find
this file of the "Application.StartupPath" ?
--
thanks in advance!

Mika
Hi,

System.Reflection.Assembly.GetExecutingAssembly(). Location + "\
\settings.xml";
Aug 7 '08 #3
On Aug 7, 9:21*am, "John Vottero" <JVott...@mvpsi.comwrote:
"Mika M" <mika.mahonen_removet...@gmail.comwrote in message

news:Oh****************@TK2MSFTNGP02.phx.gbl...


Hi!
I have made quite simple Windows Service using C# 2005. I also made Setup
for it into same solution. When I run Setup, it will be installed ok into
C:\Program Files\<MyCompany>\<MyService>.
Setup is also installing self made default "settings.xml"-file into the
same directory. It contains DataTable for the service how to work, that
service is reading into DataTable-object when it is started. These
settings are not same as <MyService>.exe.config settings.
Now the problem is that Service is trying to find this "settings.xml"-file
of the C:\WINDOWS\System32 instead of C:\Program
Files\<MyCompany>\<MyService-path, when my "settingsHandler"-class
contains declaration...
private const string FILE_PATH = "settings.xml";

private const string FILE_PATH =
* * * * * * * * System.AppDomain.CurrentDomain.BaseDirectory +
"settings.xml";- Hide quoted text -

- Show quoted text -
you are missing the \ between the foldername and the file name
Aug 7 '08 #4
"Ignacio Machin ( .NET/ C# MVP )" <ig************@gmail.comwrote in
message
news:b8**********************************@d45g2000 hsc.googlegroups.com...
On Aug 7, 9:21 am, "John Vottero" <JVott...@mvpsi.comwrote:

[snip]
>>
private const string FILE_PATH =
System.AppDomain.CurrentDomain.BaseDirectory +
"settings.xml";- Hide quoted text -

- Show quoted text -

you are missing the \ between the foldername and the file name
No I'm not, BaseDirectory includes the trailing \.

Aug 7 '08 #5
On Aug 7, 2:47*pm, "John Vottero" <JVott...@mvpsi.comwrote:
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mac...@gmail.comwrote in
messagenews:b8**********************************@d 45g2000hsc.googlegroups..com...
On Aug 7, 9:21 am, "John Vottero" <JVott...@mvpsi.comwrote:

[snip]
private const string FILE_PATH =
System.AppDomain.CurrentDomain.BaseDirectory +
"settings.xml";- Hide quoted text -
- Show quoted text -
you are missing the \ between the foldername and the file name

No I'm not, BaseDirectory includes the trailing \.
sorry for the error, you are right.
You have another error though, you can only assign a constant to a
constant string.
Aug 8 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jon | last post: by
2 posts views Thread by R A | last post: by
4 posts views Thread by SQLScott | last post: by
3 posts views Thread by adasilva | last post: by
reply views Thread by niclarke | last post: by
2 posts views Thread by rqcoder | last post: by
1 post views Thread by serge calderara | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.