-3

I'm getting the 'cannot be found' error although the file does exist and the path is right. I have tried AudiosInfo.txt.txt and it does not work.

FileStream f = new FileStream("AudiosInfo.txt", FileMode.Open);
StreamReader s = new StreamReader(f);
string l=s.ReadLine();
MessageBox.Show(l);
MethodMan
  • 18,625
  • 6
  • 34
  • 52

3 Answers3

1

When you are using,

FileStream f = new FileStream("AudiosInfo.txt", FileMode.Open);

you have to ensure that, AudiosInfo.txt file must be stored in your solution's \bin\Debug folder.

Otherwise you have to give the full path.

Abhilash Ravindran C K
  • 1,818
  • 2
  • 13
  • 22
0

This is how you can find the full path: right click on the AudiosInfo.txt file, click on properties, click on the details tab and take a look at the folder path.

Susha Naidu
  • 307
  • 1
  • 3
  • 16
  • Actually what is the error? That the txt.file cannot be found? Can you please update the codes with the full path? – Susha Naidu Nov 29 '17 at 01:02
-1

Might need to use to find the the path

string filePath = @"C:\MyDir\MySubDir\myfile.ext";
string directoryName;
int i = 0;

while (filePath != null)
{
    directoryName = Path.GetDirectoryName(filePath);
    Console.WriteLine("GetDirectoryName('{0}') returns '{1}'",
        filePath, directoryName);
    filePath = directoryName;
    if (i == 1)
    {
        filePath = directoryName + @"\";  // this will preserve the previous path
    }
    i++;
}
/*
charithsuminda
  • 341
  • 2
  • 9