Click here to Skip to main content
15,906,097 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to save Error logs in text file. But i am getting error

Illegal characters in path.


Path seems ok .

private ExceptionHandler()
        {
            string exePath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            _StreamWriter = new StreamWriter(Path.Combine(exePath, "E:\test.txt"));
        }


What I have tried:

I have a test.txt file in E drive . The path is ok but i am getting error
Illegal characters in path
Posted
Updated 15-Apr-17 16:26pm
Comments
[no name] 15-Apr-17 20:58pm    
That is because the path is invalid.

in "E:\test.txt", \t have special meaning.
you need to use
C#
"E:\\test.txt"

It is C language family behavior, '\' is used for special chars.
 
Share this answer
 
v2
In addition to what was mentioned in the other solution, you are trying to append a fully qualified path to another fully qualified path. You can't do that.

Also, the path you got from location includes the executable name. That's not going to work for you either. If you want the path to the folder the .EXE was launched from, you need to remove the .EXE at the end of the path first.
C#
var exePath = Assembly.GetEntryAssembly().Location;
var folder = Path.GetDirectoryName(exePath);
var logPath = Path.Combine(folder, "test.txt");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900