-
Illegal characters
I have a text file that contains settings, such as the output file location. Then I call the file in my program...
File.AppendAllText(@PIoutput, "5," + time.Year + "," + time.DayOfYear + "," + time.ToString("HHmm").TrimStar('0') + "," + time.Second);
When the program runs, I get the error "Illegal characters in path."
-
Re: Illegal characters
You don't need to use the string literal operator (@) on a variable. Remove it and see if that works. Usually you would see it's use only when you are inputting a new string that you don't want escaped e.g. string blah = @"this\string\shouldn't\be\escaped";
Failing that, what is the value of PIoutput? Certain characters are not allowed in file paths such as any of:
-
Re: Illegal characters
I took the "@" out and it still did not work. My output file is defined in the text file as.... string.Format("{0}{1}Metdata_MT-{2:yyyy-MM-dd}.txt", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), Path.DirectorySeparatorChar, DateTime.Now)
Per what you said, I am assuming this is what is causing the error. lol. But how do I set the output file to this format?
-
Re: Illegal characters
Hrm. I see nothing obviously wrong with that. What value does PIoutput have in the debugger?
-
Re: Illegal characters
Ok in my text file, I put the file location. In my program, I called it with
"output=line + string.Format("{0}{1}Metdata_MT-{2:yyyy-MM-dd}.txt");
I get the error message FormatException was unhandled. Whats wrong here?
-
Re: Illegal characters
It's because you use string.Format with {#}'s in the string and then do not provide them as arguments.
Go back to your original example and set
Code:
string PIOutput = string.Format("{0}{1}Metdata_MT-{2:yyyy-MM-dd}.txt", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), Path.DirectorySeparatorChar, DateTime.Now)
Then use the debugger to see the value assigned to PIOutput and post it here (or examine it and figure out why it's an invalid path).