Thread
Print

Copy files from a folder to anothers by c#

Copy files from a folder to anothers by c#

Introduction
In this sample,It shows how to move files to another folder.

Background
It can be used in winForm applications.

Using the code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace www.treaple.com
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.ShowDialog();
            ImportGISFiles(folderBrowserDialog1.SelectedPath, txtDPath.Text, txtDFolder.Text);
        }

        public void ImportGISFiles(string sourcePath, string destinationPath, string destinationFolder)
        {
            if (Directory.Exists(destinationPath + destinationFolder))
                Directory.Delete(destinationPath + destinationFolder, true);

            Directory.CreateDirectory(destinationPath + "\\" + destinationFolder);

            string[] fileArray = Directory.GetFiles(sourcePath);
            string fileName = null;
            for (int i = 0; i < fileArray.Length; i++)
            {
                fileName = Path.GetFileName(fileArray);
                File.Copy(fileArray, destinationPath + "\\" + destinationFolder + "\\" + fileName, true);
            }
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.
            Process.Start("http://www.treaple.com/About_Us.htm");
        }
    }
}

History
If you have any questions,You are welcomed to contact me by email or visit my own site www.treaple.com .

Attachment

Sample.zip (29.43 KB)

6-26-2008 01:10, Downloaded count: 52

TOP

Thread