no Startuppath or 'using System.Windowsforms' ?

Good Morning,

I've got a service with should open a non specific directory. At framework 1.1 there was a method Application.StartUppath (or something like this), this need to use the System.Windowsform. But it's not in the list with the suggested namespaces. How should I open my XML-File out of my application folder, if i can't get the foldername please help



Answer this question

no Startuppath or 'using System.Windowsforms' ?

  • KPC

    You need to add a reference to System.Windows.Forms.dll, however, it would be crazy to bring an entire dll (quite a large one) into the process just to get the startup path from Application. So instead, do the following:



    using System.IO;
    using System.Reflection;
    [...]

    string startupPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);



  • wyzec

    ok, thanks. But I make a Setup to install this service. The XML-File is located at Programs/bla/setting.xml (the installation path). Do I get with your method, this folder, oder the path where the Service (like windows/...) is located


  • Yahweh

    This folder will return the folder where the actual service is located. If you want to return a installation folder, you perhaps need to store the installation path in a registry key during the installation and read from that.

  • no Startuppath or 'using System.Windowsforms' ?