user2890732
user2890732

Reputation: 9

c# variable and string for file location cannot join

I have the string below that works fine:

/* Upload a File */
ftpClient.upload(GetPublicIpAddress() + ".stats." + userName + ".dat", @"C:\Users\variable\AppData\Roaming\miner\stants.dat");

I am trying to change it so where it says

users\variable\AppData

it substitutes the user's name for 'variable'. I have this below

variable = userName
/* Upload a File */
ftpClient.upload(GetPublicIpAddress() + ".stats." + userName + ".dat", @"C:\Users\"+ userName +"\AppData\Roaming\miner\stants.dat");

I get the following error

Error   3   Unrecognized escape sequence    C:\ConsoleApplication1\Program.cs   

Upvotes: 0

Views: 57

Answers (2)

Luis Tellez
Luis Tellez

Reputation: 2983

You need to use @ after the userName when you concatenate it.

Upvotes: 1

Bill Gregg
Bill Gregg

Reputation: 7147

You are missing a second @ symbol.

ftpClient.upload(GetPublicIpAddress() + ".stats." + userName + ".dat", @"C:\Users\"+ userName +@"\AppData\Roaming\miner\stants.dat");

Once you split the string into 2, you need to prefix both strings with @.

Upvotes: 6

Related Questions