C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » File Operations »

Get all files in Directory and Sub directory using Asp.net


Posted Date: 06 Oct 2009    Resource Type: Code Snippets    Category: File Operations
Author: Srikanth ReddyMember Level: Silver    
Rating: 1 out of 5Points: 10



Get all files in Directory and Sub directory using Asp.net

using System.IO;

public void GetFiles(string path)

{

if (File.Exists(path))

{

// File path

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 + "
");

position++;

}

/*To use the methods just call the following method with our base/root directory:

GetFiles("C:\\Test\\");*/



Responses

Author: Srikanth Reddy    06 Oct 2009Member Level: Silver   Points : 1
To use the methods just call the following method with our base/root directory:

GetFiles("C:\\Test\\");


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Retrieve all files from directory and sub directory  .  Get all files in Directory and Sub directory using Asp.net  .  Display all the files from directory and subdirectory  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Reading a Word file..
Previous Resource: Load Assembly
Return to Discussion Resource Index
Post New Resource
Category: File Operations


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use