How to Retrieve all file names and write to TextFile

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lenniekuah
    New Member
    • Oct 2006
    • 126

    How to Retrieve all file names and write to TextFile

    Hi Good Guys,
    I need your help. Please help me.

    My office BA requested me to develop Window application to retrieve all the files from the SalesDepartment folder : F:\SalesDept and write the name of the file into a TextFile and save it into this folder F:\StoreFileNam e\

    I have not written this type of coding before and I need your help to show me sample coding in order for me to learn something new.

    Thank You,

    Cheers,
    Lennie
  • Subin Ninan
    New Member
    • Sep 2010
    • 91

    #2
    This is how you can do it in C#.

    Code:
    FileStream fs = new FileStream(@"F:\StoreFileName\FileList.txt", FileMode.Create, FileAccess.Write);
    StreamWriter writer = new StreamWriter(fs);
    foreach (string file in Directory.GetFiles(@"F:\SalesDept"))
    {
       writer.WriteLine(file.ToString());
    }
    writer.Close();
    fs.Close();

    Comment

    • lenniekuah
      New Member
      • Oct 2006
      • 126

      #3
      Hullo Subin Ninan,

      What the Project Reference file name ?

      Thank you very much for helping with the sample coding. You are awesome, wonderful and very helpful. I will learn this logical technology by trying it out. I will get back to you after putting it on my application.

      I will post the working coding here to share with other Newbies who may have similar problem in appreciation of your help.

      Thank you and Have a Good Day.

      Cheers,
      Lennie
      Last edited by lenniekuah; Sep 26 '10, 09:08 PM. Reason: complete statement

      Comment

      Working...