Last post Jun 29, 2014 03:31 AM by Mikesdotnetting
Jun 28, 2014 06:53 PM|Markus33|LINK
Error created when tryin to access file!!! Pleaze help.
MSDN A FileNotFoundException exception is thrown when an attempt is made to access a file or directory that does not exist on disk.
If the file does not exist, this exception is thrown. For more information, see FileExists.
If you are assuming the current directory incorrectly, relative paths will be incorrect as well.
I need help with accessing file from visual studio, this is where my file is place inside of my visual studio(solution explorer)! The following is my file path...
c:\users\andrew\documents\visual studio 2012\MyTemplates\Form1\Form1\Test.txt
The following explains the error...
// Open a new stream.
using (System.IO.StreamReader myStream = new System.IO.StreamReader(SourceFile)) ///File not found exception was unhandled by user code. Could not find file C:\Test.txt
// Process lines while there are lines remaining in the file.
e.Cancel = true;
line = myStream.ReadLine();
WordCount += CountInString(line, CompareString);
LinesCounted += 1;
// Raise an event so the form can monitor progress.
int compare = DateTime.Compare(
if (compare > 0)
state.LinesCounted = LinesCounted;
state.WordsMatched = WordCount;
lastReportDateTime = DateTime.Now;
// Uncomment for testing.
Jun 29, 2014 03:31 AM|Mikesdotnetting|LINK
You need to make sure that the value of 'SourceFile' is correct. At the moment, your application thinks it should be C:\Test.txt. So you have set the value incorrectly.