none
file system RRS feed

  • Question

  • i would like to know the  code to access  files from folder and subfolders also and i ant to stored in array in sorted form and then print
    Wednesday, May 12, 2010 5:08 AM

Answers

  • Hi,

    I didnt understand your statement completly, but following piece of code might help.

          string FolderPath = @"C:\Test";
          string[] allFiles = Directory.GetFiles(FolderPath, "*", SearchOption.AllDirectories);

    Regards,

    Vinil;

     

    • Proposed as answer by Skpananghat Wednesday, May 12, 2010 6:54 AM
    • Marked as answer by SamAgain Friday, May 14, 2010 2:04 AM
    Wednesday, May 12, 2010 6:22 AM
  • Hi,

    You can try this you can get your answer:- You will have to add Imports System.IO in TOP of the page

    Dim objfileColl As New System.Collections.ObjectModel.Collection(Of IO.FileInfo)

    Dim dirInfo As New IO.DirectoryInfo("C:\WF") 'Please change the folder path

    Dim fileName As IO.FileInfo() = dirInfo.GetFiles()

    Dim dr, item As IO.FileInfo

    'store in array or collection

    For Each dr In fileName

    objfileColl.Add(dr)

    Next

    'print from collection

    For Each item In objfileColl

    Response.Write(item.ToString & "<br>")

    Next

    Thanks

    Amit

    • Marked as answer by SamAgain Friday, May 14, 2010 2:04 AM
    Wednesday, May 12, 2010 6:33 AM
  • Hi,

    Also You can add following code into Vinil Code:-

    For

    Each(String a In allFiles) {

    Response.Write(a.ToString & "<br>")

    }

     

    Thanks

    Amit

    • Marked as answer by SamAgain Friday, May 14, 2010 2:04 AM
    Wednesday, May 12, 2010 6:50 AM

All replies

  • Hi,

    I didnt understand your statement completly, but following piece of code might help.

          string FolderPath = @"C:\Test";
          string[] allFiles = Directory.GetFiles(FolderPath, "*", SearchOption.AllDirectories);

    Regards,

    Vinil;

     

    • Proposed as answer by Skpananghat Wednesday, May 12, 2010 6:54 AM
    • Marked as answer by SamAgain Friday, May 14, 2010 2:04 AM
    Wednesday, May 12, 2010 6:22 AM
  • Hi,

    You can try this you can get your answer:- You will have to add Imports System.IO in TOP of the page

    Dim objfileColl As New System.Collections.ObjectModel.Collection(Of IO.FileInfo)

    Dim dirInfo As New IO.DirectoryInfo("C:\WF") 'Please change the folder path

    Dim fileName As IO.FileInfo() = dirInfo.GetFiles()

    Dim dr, item As IO.FileInfo

    'store in array or collection

    For Each dr In fileName

    objfileColl.Add(dr)

    Next

    'print from collection

    For Each item In objfileColl

    Response.Write(item.ToString & "<br>")

    Next

    Thanks

    Amit

    • Marked as answer by SamAgain Friday, May 14, 2010 2:04 AM
    Wednesday, May 12, 2010 6:33 AM
  • Hi,

    Also You can add following code into Vinil Code:-

    For

    Each(String a In allFiles) {

    Response.Write(a.ToString & "<br>")

    }

     

    Thanks

    Amit

    • Marked as answer by SamAgain Friday, May 14, 2010 2:04 AM
    Wednesday, May 12, 2010 6:50 AM