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 8924905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:32:59+00:00 2026-06-15T07:32:59+00:00

hey i am currently converting my functions from console program to windows service program

  • 0

hey i am currently converting my functions from console program to windows service program and have trouble with reading my settings.xml file and write the log file.

how do i specify where the program will look for the files? it would be great if it could work like in my console version when the program looks in the map from where it is started from.

can you do this in windows service program to look in the map from where i installed the service?

This is how the functions look like right now

public List<string> GetSettingsXml()  //Läser settings.xml som innehåller företags sökvägarna som behövs för att öppna kontakten till visma adminitration
    {
        List<string> PathList = new List<string>();
        try
        {
            XmlReader xr;
            using (xr = XmlReader.Create("Settings.xml")) //Läs från Settings.xml
            {
                while (xr.Read())   //Läser xml filen till slutet
                {
                    if (xr.HasValue)    //om den har ett värde så...
                    {
                        if ((!String.IsNullOrWhiteSpace(xr.Value)))
                        {
                            PathList.Add(xr.Value.ToString()); //plockar ut alla värden i xml filen
                        }
                    }
                }
            }

        }
        catch (Exception e)
        {
            WriteToLog("127.0.0.1", "GetSettings", "Exception", e + ": " + e.Message);
        }
        return PathList;
    }

And the other

public void WriteToLog(string ip, string FunctionName, string Keyfield, string Result)   //skapar log filen om den inte finns och skriver i den
    {
        if (ip != "127.0.0.1")
        {
            OperationContext context = OperationContext.Current;
            MessageProperties prop = context.IncomingMessageProperties;
            RemoteEndpointMessageProperty endpoint = prop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
            ip = endpoint.Address;
        }
        string Today = DateTime.Today.ToString().Remove(10);
        StreamWriter log;

        if (!File.Exists("logfile " + Today + ".txt"))
        {
            log = new StreamWriter("logfile " + Today + ".txt");
        }
        else
        {
            log = File.AppendText("logfile " + Today + ".txt");
            log.WriteLine();
        }

        log.Write(DateTime.Now + " ::: " + ip + " ::: Funktions namn: " + FunctionName);
        if (Keyfield != "NoKeyField")
            log.Write(" ::: Nyckelfält: " + Keyfield + " ::: Resultat: " + Result);
        else
            log.Write(" ::: Resultat: " + Result);
        if (FunctionName == "host.Close()")
            log.WriteLine();

        log.Close();   //stäng loggen
    }

how will i make my service know where the files are? 🙂
thank you for answers

EDIT

[RunInstaller(true)]
public class WindowsServiceInstaller : Installer
{
    /// <summary>
    /// Public Constructor for WindowsServiceInstaller.
    /// - Put all of your Initialization code here.
    /// </summary>
    public WindowsServiceInstaller()
    {
        ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();
        ServiceInstaller serviceInstaller = new ServiceInstaller();

        //# Service Account Information
        serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
        serviceProcessInstaller.Username = null;
        serviceProcessInstaller.Password = null;

        //# Service Information
        serviceInstaller.DisplayName = "VenatoWCF";
        serviceInstaller.Description = "VenatoWCF 0.903 skapar en WCF service som med hjälp av olika funktioner kommunicerar mellan Visma Administration och Client";
        serviceInstaller.StartType = ServiceStartMode.Automatic;

        //# This must be identical to the WindowsService.ServiceBase name
        //# set in the constructor of WindowsService.cs
        serviceInstaller.ServiceName = "VenatoWCF";

        this.Installers.Add(serviceProcessInstaller);
        this.Installers.Add(serviceInstaller);
    }
}

this is my installer if that helps

  • 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-06-15T07:33:01+00:00Added an answer on June 15, 2026 at 7:33 am

    how do i specify where the program will look for the files?

    .NET looks for files in Environment.CurrentDirectory if no path was specified. The directory depends on how the application was started.

    If you for instance run the application from within Visual Studio the folder will be the Output Path (under project settings / build), while for windows services it will be the directory that the service exists in.

    Windows services are started from the folder where the Service Control Manager is located (source: What directory does a Windows Service run in?).

    You can find your own directory by using Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey I am currently reading in a XML file which contains bullet list in
Hey there, I have a big code file currently in C++ with many functions
hey i am currently just to get the data from the file for example
Hey I have an ajax call which currently calls a php file with queries
Hey All I currently have a problem with my insert php file I have
Hey guys I have a query that currently finds the latest comment for each
Hey guys quick question, I currently have an insert statement $query= INSERT into new_mail
Hey guys, I currently present my mp3s by referencing their file location into a
Hey, I currently have a Currency Format method: private string FormatCurrency(double moneyIn) { CultureInfo
Hey, I currently am having trouble trying to get this to work. Here's a

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.