I am facing problem while trying to open a simple text file in C#. What i tried so far includes:
- Change the location of file from C dir to D dir.
- Place file inside a folder
- Check its properties and its not read only
- Create new text file from scratch
- Code in C instead of C#
but all the above variations failed and i got the same exception “That file not found”. I am not sure whats wrong there. Its might be some bug in windows 7 or may be some security feature of windows 7 which prevents file from being accessed inside code.
Any help would be highly appreciated.
Edit:
Code in C
FILE *pFile;
pFile = fopen("d:\\test\\series.txt", "r");
if (pFile == NULL)
{
printf("File not found or Unable to open file\nPress any key to continue . . ." );
getch();
return;
}
else
{
// do processing here
}
C# Code:
string[] AllLines = System.IO.File.ReadAllLines("D:\\test\\data.txt");
It’s possible the path isn’t right. Check your file path string, use either the ‘@’ prefix to make it literal, or escape your backslashes as Jeff M suggested.
or