Charlotte Vancraeynest
Charlotte Vancraeynest

Reputation: 339

c# Relative path

Hello I have a program made in Visual Studio in C#. In this program I have some pictures that need to be called. And some html files that need to be saved. All these files are saved in the map 'mails'. At the moment I have the path:

 String pad = @"C:\Users\Charlotte\Desktop\proof of concept\mails\";

I need this path to be relative so the user of the program can just copy the map mails to wherever he/she wants it and execute the exe of my program and just work with it.

Can anyone help me?

Upvotes: 2

Views: 979

Answers (3)

Atish Kumar Dipongkor
Atish Kumar Dipongkor

Reputation: 10422

try it

string path = @"..\..\mails\";

Upvotes: 0

Łukasz Motyczka
Łukasz Motyczka

Reputation: 1199

If the user places a file wherever he wants, you need to tell your program where it is aomehow. So if you use OpenFile dialog your path would be:

string pad = openFileDialog1.FileName;

On the other hand if you mean that a path should be relative to your exe file you would use:

string pad = Application.StartupPath + "\\mails\\";

This will mean that a path is a directory of your exe \mails, but without a name of the file.

Upvotes: 2

atthakorn
atthakorn

Reputation: 168

You can use function: Directory.GetCurrentDirectory() to get the path of current directory instead of telling program the fullpath.

Upvotes: 4

Related Questions