SEO Software
Closed Thread
Results 1 to 6 of 6

Thread: Listing file in directory usign Asp.net

  1. #1

    Default Listing file in directory usign Asp.net

    I want to list all files and subdirectories available in particular directory? Is it possible to do it using asp.net? I am usign c# with the asp.net.

    THank you


  2. #2

    Default

    You can use directoryinfo and fileinfo class of System.io namespace

    Following code will display files in listbox

    PHP Code:
    DirectoryInfo dirCustom = new DirectoryInfo(txtPath.Text);
    FileInfo[] filCustom;

      
    filCustom dirCustom.GetFiles("*.*");


    foreach (
    FileInfo filFile in filCustom)

    {
       
    listbox1.items.add(filfile.name);



  3. #3

    Default

    i think its not bossible to list all the files and sub directories in the particular directory in asp.net

  4. #4

    Default

    it is possible through the listbox control.then place the listbox control then goto edit items property.then click add items

  5. #5

    Red face

    well i don't know the answer of that..
    and techkid have given you the answer..
    i think that's the only way to do that...
    still i have not tried it but its just a suggestion...

  6. #6

    Default

    Try out this code.
    public void GetFiles(string path)

    {

    if (File.Exists(path))

    {

    // This path is a file

    ProcessFile(path);

    }

    else if (Directory.Exists(path))

    {

    // This path is a directory

    ProcessDirectory(path);

    }

    }



    // Process all files in the directory passed in, recurse on any directories

    // that are found, and process the files they contain.

    public void ProcessDirectory(string targetDirectory)

    {

    // Process the list of files found in the directory.

    string[] fileEntries = Directory.GetFiles(targetDirectory);

    foreach (string fileName in fileEntries)

    ProcessFile(fileName);



    // Recurse into subdirectories of this directory.

    string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory);

    foreach (string subdirectory in subdirectoryEntries)

    ProcessDirectory(subdirectory);

    }



    // Insert logic for processing found files here.

    public void ProcessFile(string path)

    {

    FileInfo fi = new FileInfo(path);

    Response.Write("File Number " + position.ToString() + ". Path: " + path + " <br />");

    position++;

    }

Closed Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts