TextReader in c# RRS feed

  • Question

  • Hello!

    I want to read a .DAT file line by line in C#.

    For that I have created a TextReader's object named 'tr'.

    If I give the following instruction then its working fine.

    tr = new StreamReader(@"D:\AxisImages\25-03-2010\25-03-2010.DAT");

    file has given the current date as a name. therefore "25-03-2010.DAT".

    But If I accept the date from user and give the following command i.e.

    tr = new StreamReader(@"D:\AxisImages\"+date+@"\"+date+".DAT");

    then its throwing an exception as "DirectoryNot FoundException".

    I have verified the path and all. They all are right.. . but still an instruction is not working fine..

    What can be the problem?

    Thank you!

    Monday, March 29, 2010 10:00 AM


  • Print the string to console to verify that it is really what you think it is. Make sure that the directory and file really exist (at that moment).

    If it doesn't help, use Process Monitor to see which directory/file is not opened and why.


    • Marked as answer by SamAgain Wednesday, April 7, 2010 10:29 AM
    Tuesday, March 30, 2010 5:11 AM

All replies