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.
AttachmentsFolderCopy (30752-25122-FileCopy.rar)
|
No responses found. Be the first to respond and make money from revenue sharing program.
|