C# Tutorials and offshore development in India
Tutorials Resources Forum Reviews Communities Interview Jobs Projects Training Your Ad Here


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

Folder copy


Posted Date: 25 Jul 2009    Resource Type: Articles    Category: .NET Framework
Author: ABitSmartMember Level: Diamond    
Rating: 1 out of 5Points: 3



I have attached a Folder copy utility to copy a folder from one location to another.

The utility contains two buttons to read the Source and Destination path.

private void button1_Click(object sender, EventArgs e)
{
string folderSelected = GetFolderPath();
if( !String.IsNullOrEmpty(folderSelected))
textBox1.Text = folderSelected;
}

private void button2_Click(object sender, EventArgs e)
{
string folderSelected = GetFolderPath();
if (!String.IsNullOrEmpty(folderSelected))
textBox2.Text = folderSelected;
}

private string GetFolderPath()
{
// Show the FolderBrowserDialog.
FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();

DialogResult result = folderBrowserDialog1.ShowDialog();
if (result == DialogResult.OK)
{
return folderBrowserDialog1.SelectedPath;
}

return string.Empty;
}


The above code opens the Folder browser dialog and requests the path.

The final button does the copy from the source to the destination folder.

private void button3_Click(object sender, EventArgs e)
{

if (!String.IsNullOrEmpty(textBox1.Text) && !String.IsNullOrEmpty(textBox2.Text))
{
if (Directory.Exists(textBox1.Text) )
{
Directory.Move(textBox1.Text, textBox2.Text);
MessageBox.Show("Folder moved!");
}
else
MessageBox.Show("Source or destination does not exist!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
MessageBox.Show("Source or destination is empty!","Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}


Please see refer to the attached sample for a working copy of the sample.

Have fun.

Attachments

  • FolderCopy (30752-25122-FileCopy.rar)


  • Responses to the resource: "Folder copy"

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

    Feedbacks      
    Popular Tags   What are tags ?   Search Tags  
    Sign In to add tags.
    .Net Folder copy  .  

    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: Simple File Search Using LINQ
    Previous Resource: Debug ASP.NET Without IIS in Visual Studio.NET
    Return to Discussion Resource Index
    Post New Resource
    Category: .NET Framework


    Post resources and earn money!
     
    More Resources




    About Us    Contact Us    Privacy Policy    Terms Of Use