Reputation: 93
I'm making a simple command program, and while trying to create a directory, I'm getting the error that there is invalid characters in the path, I'm guessing the NetworkStream added invisible characters?
Code:
Console.WriteLine(">> Recieved: " + Encoding.ASCII.GetString(data, 0, data.Length));
byte[] back = null;
if (Encoding.ASCII.GetString(data, 0, data.Length).Contains("cd "))
{
try
{
back = Encoding.UTF8.GetBytes(">> Created Directory");
stream.Write(back, 0, back.Length);
string dir = Encoding.ASCII.GetString(data, 0, data.Length).Replace("cd ", "");
Directory.CreateDirectory(dir);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
EXACT ERROR: System.Argument Exception, Illegal Characters at Path
Upvotes: 0
Views: 173
Reputation: 942408
Put dir.ToCharArray()
in the debugger watch expression. You'll now see the individual character codes, including the non-printable ones like 0.
Upvotes: 1