-
December 19th, 2011, 09:14 AM
#1
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."
-
December 19th, 2011, 11:21 AM
#2
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:
Best Regards,
BioPhysEngr
http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
-
December 19th, 2011, 11:33 AM
#3
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?
-
December 19th, 2011, 10:03 PM
#4
Re: Illegal characters
Hrm. I see nothing obviously wrong with that. What value does PIoutput have in the debugger?
Best Regards,
BioPhysEngr
http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
-
December 21st, 2011, 01:12 PM
#5
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?
-
December 22nd, 2011, 01:48 AM
#6
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).
Best Regards,
BioPhysEngr
http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|