Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7572097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:50:20+00:00 2026-05-30T15:50:20+00:00

I have created a windows service in c# .Net 4.0. In VS it works

  • 0

I have created a windows service in c# .Net 4.0.

In VS it works great, I have built the project and installed the exe as a service which does run.

I have found that when operating as a service the application does not reference application configuration files I have placed in the same directory as the service exe.

If I strongly type the full file path in code there is no problem, however this is not an ideal solution as users could install things where ever they like.

How can I make the application reference (look for) files local to the EXE and not I assume where the .Net service wrapper is located.

Nothing seems to be helpful on google.

Example

Does Work:

var config =
                    ClassLib.XmlInterface.DeserializeConfiguration(
                        "C:\\Users\\Damo\\Documents\\Visual Studio 2010\\Projects\\FileDownloadService\\FileDownloadService\\bin\\Debug\\config.xml");

Does not work: (dispute been local to the EXE)

var config =
                    ClassLib.XmlInterface.DeserializeConfiguration(
                        "config.xml");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T15:50:22+00:00Added an answer on May 30, 2026 at 3:50 pm

    There are a couple of ways to resolve this.

    You could create an environment variable, and read the path from it. This is kind of kludgy, if you don’t have a Setup application, and it’s prone to breakage if users muck with their settings. But it will work if you do it correctly.

    If you have a setup application, you could also store the path to your executable in the Registry, and read it at runtime.

    Or, you can try retrieving the path to your assembly at runtime using something like this:

        public static string GetCoreAssemblyPathRoot()
        {
            const string AssemblyName = "MyAssemblyName,";
            var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
            var path = (from assembly in loadedAssemblies
                        where assembly.FullName.StartsWith(AssemblyName)
                        select Path.GetDirectoryName(assembly.Location))
                       .FirstOrDefault();
            if (path == null)
            {
                return null;
            }
            //  The last part of the path is "\bin". Remove it, and return the remainder.
            var index = path.IndexOf("\\bin\\");
            return index == -1
                       ? path
                       : path.Substring(0, index);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a .NET Windows service which has a WCF service built into
I have created a Windows Service in VB.net for building xML from a database.
Currently, I have a project with a Windows Service. I also created another Setup
I have created a new VS2008 ASP.Net Web service project, with the default name
I have a Windows Service created in .NET 4. I need to access a
I have created a wcf service which is deployed via a managed windows service.
I have a .NET windows service which acts as a host for some wcf.
I have a .NET Windows service which self hosts a WCF service. This WCF
I've implemented quartz.net in windows service to run tasks. And everything works fine on
I have created a C# Windows service but it fails to start. I get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.