Windows Service startup path for settings

M

Mika M

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" ?
 
J

John Vottero

Mika M said:
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";
 
I

Ignacio Machin ( .NET/ C# MVP )

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" ?

Hi,

System.Reflection.Assembly.GetExecutingAssembly().Location + "\
\settings.xml";
 
I

Ignacio Machin ( .NET/ C# MVP )

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
 
I

Ignacio Machin ( .NET/ C# MVP )

message
[snip]


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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top