C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Copy directory recursively in C#


Posted Date: 28 Jul 2008    Resource Type: Articles    Category: .NET Framework

Posted By: VijayKumar Reddy M       Member Level: Gold
Rating:     Points: 6



This code sample can be used to copy the files from one server to another server. While copying a directory, sub-directories are recursed.

Step 1:
In Button1_click event


copyDirectory(@"c:\temp", @"c:\ResultTemp");


Step 2:


public static void copyDirectory(string Src, string Dst)
{
String[] Files;

if (Dst[Dst.Length - 1] != Path.DirectorySeparatorChar)
Dst += Path.DirectorySeparatorChar;
if (!Directory.Exists(Dst)) Directory.CreateDirectory(Dst);
Files = Directory.GetFileSystemEntries(Src);
foreach (string Element in Files)
{
// Sub directories
if (Directory.Exists(Element))
copyDirectory(Element, Dst + Path.GetFileName(Element));
// Files in directory
else
File.Copy(Element, Dst + Path.GetFileName(Element), true);
}
}




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Work in Microsoft  .  Copying directories from a server  .  Copy files from one server  .  Copy directories recursively  .  Copy directories  .  

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: About Delegates and Anonymous methods in C#
Previous Resource: Service-Oriented Architecture and Microsoft .NET
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use