Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
```string readText = File.ReadAllText(path);```

I placed the path in but at first it was spamming errors that none of the words existing in the context so i place din some speechmarks and it was not accepting backslashes in the path.

What I have tried:

I tried placing the pathway directly from the add to program functionality on the right
and then trying to place the path it gave , and nope still same error.
Posted
Updated 30-Aug-19 18:43pm
v3

1 solution

Quotes won't help you at all: in C# the quote character delimits single character literal values: 'a', 'B', '1'
Putting them round a line of code won't help.

So try something like this:
C#
string path = @"D:\Test Data\MyFile.txt";
string allTheText = File.ReadAllText(path);
The '@' in front of the string disables string escaping, which is a way of getting special characters like double quotes and newlines into strings.
Alternatively, leave strignescaping on, and use it to "double up" and generate a backslash:
C#
string path = "D:\\Test Data\\MyFile.txt";
string allTheText = File.ReadAllText(path);
You will get the same results.
 
Share this answer
 
Comments
HamzaMcBob 31-Aug-19 7:54am    
@"path" worked , I was tired lmao

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