Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a file path in C#

Tags:

c#

file-io

So I'm trying to create a path in C#. I use Environment.Machinename and store it a variable serverName. Then I create another string variable and have some other path extension in there. Here is my code so far:

string serverName = Environment.MachineName;
string folderName = "\\AlarmLogger";

No matter what I do I can't seem to obtain only one backslash prior to AlarmLogger. Any ideas how I can specify a path in C#?

Edit: I'm wondering if my code doesn't seem to want to paste correctly. Anyways when i paste it I only see one backslash but my code has two. Because of the escape character sequence. But something like

string test = @"\\" + serverName + folderName 

doesn't seem to want to work for me.

like image 836
Jason Avatar asked May 22 '10 19:05

Jason


1 Answers

Use Path.Combine(serverName, folderName). Path.Combine is always a better solution than concating it on your own.

like image 74
Femaref Avatar answered Oct 02 '22 17:10

Femaref