473,322 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Relative paths in Windows Service?

Hello,

I'm developing a C# application that will be used over a network. Eventually, I want to run it as a service so that the user does not see that the program is running.

While converting a test application into a service I ran into the problem that the relative paths I defined in my code crash the service because it cannot find the files it is supposed to load.
I tried Application.ExecutablePath instead, but no luck, the service's ExecutablePath is system32, which is not where the files are.

Does anyone know what to use instead? Or will I have to use absolute paths?
Mar 23 '10 #1
2 2838
tlhintoq
3,525 Expert 2GB
problem that the relative paths I defined in my code crash
Let's see what you've done and maybe someone can point you in the right direction
Mar 23 '10 #2
Nevermind, I found an old forum post where someone suggested Assembly.GetExecutingAssembly and then work out the paths from there. The link is here: http://bytes.com/topic/c-sharp/answe...indows-service

However, I've run into another problem. My service calls a method in another class that uses System.Windows.Forms, but when I compile the project, I get the error message "The namespace 'Windows' does not exist in 'System' (is there an assembly missing?)."
The class with the System.Windows.Forms using statement needs Application.StartupPath. I need to do something like this:

String fileName = "blah.txt";
String fullPath = Application.StartupPath + fileName;

Is there something like Application.StartupPath that I can use in a Windows Service to get the path used to start the application?
Mar 30 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Doug | last post by:
If I were to write an include with a relative path like include("../conf/config.php"); What is the use? As far as I understand it, the path is relative to the first script that is called by...
7
by: mark | last post by:
I am designing a website at the moment and looking at the difference between relative and absolute url links which is driving me crazy! I would like to use relative paths, but it is proving very...
5
by: jason | last post by:
Can anyone help me find a solution to quickly working out relative paths to a folder in the root of my server... Although it easy when you go - say - two levels down: .../includes it...
1
by: olorin_press | last post by:
I have an Access 2000 database in which I display various graphics for each record. I store all the images in a folder ("Images") which is a subdirectory to the directory in which the .mdb is...
4
by: Julia | last post by:
Hi, I have two application which 'evaluate'( New FileStream(path....) relative path, when evaluating the path inside a window service it always return something like ...
2
by: Joe | last post by:
Hi, can someone tell me how to set up relativ paths in VS2003 C++ ? I have some source with a tree directory structure that segments include files in various directories: #include...
8
by: JJ | last post by:
I'm confused about paths. I have a functionn that uses the mappath method, which I think requires a virtual path (is that the same as a relative path?). But this doesn't always work as the...
15
by: Lars Eighner | last post by:
Aside from the deaths of a few extra electrons to spell out the whole root relative path, is there any down side? It seems to me that theoretically it shouldn't make any difference, and it would...
2
by: BD | last post by:
Hi there. Using 8.2 on Windows. I have a situation where I have a db backup, which I want to deploy to a group of developer workstations. The target directory for the database files will be...
2
by: Peted | last post by:
Hi i have a circumstance where a user unzips a file, with a certain layer of directories to get to a textfile. So in any directory on the HDD they may end up with something like ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.