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.
Use Path.Combine(serverName, folderName)
. Path.Combine is always a better solution than concating it on your own.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With