Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenating Environment.CurrentDirectory with back path

Tags:

c#

path

If i have the following directory structure:

Project1/bin/debug
Project2/xml/file.xml

I am trying to refer to file.xml from Project1/bin/debug directory

I am essentially trying to do the following:

string path = Environment.CurrentDirectory + @"..\..\Project2\xml\File.xml":

what is the correct syntax for this?

like image 918
leora Avatar asked Dec 06 '08 12:12

leora


People also ask

How to concatenate file path in c#?

string destFile = System. IO. Path. Combine(targetPath, fileName);

How do I change my Currentdirectory environment?

open System open System.IO if Environment. OSVersion. Platform = PlatformID. Win32NT then // Change the directory to %WINDIR% Environment.

What is path combine?

Combines an array of strings into a path. Combine(String, String) Combines two strings into a path.

What is in c# path?

C# tutorial is a comprehensive tutorial on C# language. The Path is located in the System.IO namespace. With the Path class, we can easily figure out the root path, the directory name of the file, its extension or create a random file name.


1 Answers

It's probably better to manipulate path components as path components, rather than strings:

string path = System.IO.Path.Combine(Environment.CurrentDirectory, 
                                     @"..\..\..\Project2\xml\File.xml");
like image 195
Blair Conrad Avatar answered Oct 13 '22 00:10

Blair Conrad