connectseekers.com

Wednesday, 3 September 2014

Show Progressbar While Moving Folder File From One Directory To Other Using C#.Net In Windows Application

9/03/2014 - By Pranav Singh 1

Whenever we copy file from one directory to another directory on that case Window show the progress and file detail, time remaining, no of file remains to copy and many more which were copy by user.  So this article will show you Show Progressbar While Moving Folder File From One Directory To Other Using C#.Net In Windows Application.


For this article first we will create a new windows application in this window we will add button control and label control. After adding all the controls your form will look as shown below.


Now generate the button click event. Add the code to copy file from one directory to another directory.  But before that we need to add library reference for copying the file. For that first we will right click on References folder.


Now a dialog box will open in this on .net tab select “Microsoft.VisualBasic”, select this dll and click on ok button.

After adding this reference add the below code.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.VisualBasic.FileIO;

namespace WindowsFormsApplication7
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                //Source from where we copy the file
                string sourceFolderPath = @"D:\backup\Data\Sorce";
                //Just for display purpose
                label3.Text = sourceFolderPath;
                // Destination for copied files.
                string destinationFolderPath = @"D:\backup\Data\Destignation";
                //Just for display purpose
                label4.Text = destinationFolderPath;
                FileSystem.CopyDirectory(sourceFolderPath, destinationFolderPath, UIOption.AllDialogs);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}

In above code check the Microsoft.VisualBasic.FileIO is used for FileSystem.CopyDirectory.
Now we have done run the application to check the output.


Now click on "Move File", you will get the dialogbox as shown below.


Now if you click on cancel button you will get the cancel message, Basically it's an exception which i an showing in message box.


On other hand if file moves successfully dialog box will disappear.

About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

1 comment:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com
Email Id : contact@aspdotnet-pools.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014
back to top