Windows Service startup path for settings

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mika M

    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\<MyCompan y>\<MyService> .

    Setup is also installing self made default "settings.x ml"-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.x ml"-file of the C:\WINDOWS\Syst em32 instead of C:\Program
    Files\<MyCompan y>\<MyService-path, when my "settingsHandle r"-class
    contains declaration...

    private const string FILE_PATH = "settings.x ml";

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

    Mika
  • John Vottero

    #2
    Re: Windows Service startup path for settings

    "Mika M" <mika.mahonen_r emovethis@gmail .comwrote in message
    news:OhXk$7I%23 IHA.2128@TK2MSF TNGP02.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\<MyCompan y>\<MyService> .
    >
    Setup is also installing self made default "settings.x ml"-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.x ml"-file
    of the C:\WINDOWS\Syst em32 instead of C:\Program
    Files\<MyCompan y>\<MyService-path, when my "settingsHandle r"-class
    contains declaration...
    >
    private const string FILE_PATH = "settings.x ml";
    private const string FILE_PATH =
    System.AppDomai n.CurrentDomain .BaseDirectory +
    "settings.x ml";

    Comment

    • Ignacio Machin ( .NET/ C# MVP )

      #3
      Re: Windows Service startup path for settings

      On Aug 7, 9:08 am, Mika M <mika.mahonen_r emovet...@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\<MyCompan y>\<MyService> .
      >
      Setup is also installing self made default "settings.x ml"-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.x ml"-file of the C:\WINDOWS\Syst em32 instead of C:\Program
      Files\<MyCompan y>\<MyService-path, when my "settingsHandle r"-class
      contains declaration...
      >
      private const string FILE_PATH = "settings.x ml";
      >
      ...and execution fails. How can I tell to the service it should find
      this file of the "Application.St artupPath" ?
      --
      thanks in advance!
      >
      Mika
      Hi,

      System.Reflecti on.Assembly.Get ExecutingAssemb ly().Location + "\
      \settings.xml";

      Comment

      • Ignacio Machin ( .NET/ C# MVP )

        #4
        Re: Windows Service startup path for settings

        On Aug 7, 9:21 am, "John Vottero" <JVott...@mvpsi .comwrote:
        "Mika M" <mika.mahonen_r emovet...@gmail .comwrote in message
        >
        news:OhXk$7I%23 IHA.2128@TK2MSF TNGP02.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\<MyCompan y>\<MyService> .
        >
        Setup is also installing self made default "settings.x ml"-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.x ml"-file
        of the C:\WINDOWS\Syst em32 instead of C:\Program
        Files\<MyCompan y>\<MyService-path, when my "settingsHandle r"-class
        contains declaration...
        >
        private const string FILE_PATH = "settings.x ml";
        >
        private const string FILE_PATH =
                        System.AppDomai n.CurrentDomain .BaseDirectory +
        "settings.x ml";- Hide quoted text -
        >
        - Show quoted text -
        you are missing the \ between the foldername and the file name

        Comment

        • John Vottero

          #5
          Re: Windows Service startup path for settings

          "Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin @gmail.comwrote in
          message
          news:b88e1bfc-f7c4-4572-ba85-05a45bdf549b@d4 5g2000hsc.googl egroups.com...
          On Aug 7, 9:21 am, "John Vottero" <JVott...@mvpsi .comwrote:

          [snip]
          >>
          >private const string FILE_PATH =
          >System.AppDoma in.CurrentDomai n.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 \.

          Comment

          • Ignacio Machin ( .NET/ C# MVP )

            #6
            Re: Windows Service startup path for settings

            On Aug 7, 2:47 pm, "John Vottero" <JVott...@mvpsi .comwrote:
            "Ignacio Machin ( .NET/ C# MVP )" <ignacio.mac... @gmail.comwrote in
            messagenews:b88 e1bfc-f7c4-4572-ba85-05a45bdf549b@d4 5g2000hsc.googl egroups..com...
            On Aug 7, 9:21 am, "John Vottero" <JVott...@mvpsi .comwrote:
            >
            [snip]
            >
            >
            >
            private const string FILE_PATH =
            System.AppDomai n.CurrentDomain .BaseDirectory +
            "settings.x ml";- 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.

            Comment

            Working...