16,012,110 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by AAMERSAEED (Top 12 by date)
AAMERSAEED
13-Feb-12 16:34pm
View
Thank you:)......i've done it.
AAMERSAEED
19-Dec-11 12:44pm
View
Actually now i am at home and i've win xp on my pc and i check this progress bar is working well i've checked it on 200 kb folder but in university on window 7 it appears that progress bar not finishes but stop just one step before.ie slightly before the end point??????Also suggest me if what i am doing above in this application is correct approach or not??? because i've also heard about background worker that is used for progress bars???????if i use that i don't know which code of my current application should be placed in Do_Work event???????How ever i know that do_work event contains that code which is hard task and needs to run in the background??????Please suggest me the professional way???I will always appreciate your help as your suggestion in this regard is helpfull for me.
AAMERSAEED
18-Dec-11 18:42pm
View
Hi Mika Wendelius,
First of all thanks for the cooperation. This is what i am doing and it is working but the problem is that some time progress bar stuck at the end specifically when it comes to those files which are smaller in size. Can i post the image here also??
<pre lang="c#">
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 System.IO;
namespace ProgressBarWithinClass
{
class ClassDir
{
static int maxbytes = 0;
static int copied = 0;
static int total = 0;
public static void Copy1(Label label1,ProgressBar progressBar1,string sourceDirectory, string targetDirectory)
{
DirectoryInfo diSource = new DirectoryInfo(sourceDirectory);
DirectoryInfo diTarget = new DirectoryInfo(targetDirectory);
GetSize(diSource, diTarget);
maxbytes = maxbytes / 1024;
progressBar1.Maximum = maxbytes;
CopyAll(label1,progressBar1,diSource, diTarget);
}
public static void CopyAll(Label lable1, ProgressBar progressBar1,DirectoryInfo source, DirectoryInfo target)
{
if (Directory.Exists(target.FullName) == false)
{
Directory.CreateDirectory(target.FullName);
}
foreach (FileInfo fi in source.GetFiles())
{
fi.CopyTo(Path.Combine(target.ToString(), fi.Name), true);
total += (int)fi.Length;
copied += (int)fi.Length;
copied /= 1024;
progressBar1.Step = copied;
// progressBar1.Value=copied;
progressBar1.PerformStep();
lable1.Text = (total / 1024).ToString() + "KB of " + maxbytes.ToString() + "KB copied";
lable1.Refresh();
}
foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
{
DirectoryInfo nextTargetSubDir = target.CreateSubdirectory(diSourceSubDir.Name);
CopyAll(lable1, progressBar1, diSourceSubDir, nextTargetSubDir);
}
}
public static void GetSize(DirectoryInfo source, DirectoryInfo target)
{
foreach (FileInfo fi in source.GetFiles())
{
maxbytes += (int)fi.Length;
}
foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
{
DirectoryInfo nextTargetSubDir = target.CreateSubdirectory(diSourceSubDir.Name);
GetSize(diSourceSubDir, nextTargetSubDir);
}
}
}
}
</pre>
And this is separate class i.e Form Class
<pre lang="c#">
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 System.IO;
namespace ProgressBarWithinClass
{
public partial class Form1 : Form
{
ProgressBar pBar;
Form mainform;
Label l;
public Form1()
{
InitializeComponent();
pBar = new ProgressBar();
pBar.Location = new System.Drawing.Point(20, 20);
pBar.Name = "progressBar1";
pBar.Width = 200;
pBar.Height = 30;
Controls.Add(pBar);
l = new Label();
l.Name = "label1";
l.Location = new System.Drawing.Point(50,50);
l.Height=50;
Controls.Add(l);
}
private void copybtn_Click(object sender, EventArgs e)
{
ClassDir.Copy1(l,pBar,@"D:\Sajjad", @"E:\copydata");
//CopyDir.GetInfo();
AAMERSAEED
18-Dec-11 14:49pm
View
Will you please more elaborate it for me???????Give me example?
AAMERSAEED
17-Dec-11 8:50am
View
Another question if you don't mind please tell me how can i control the progress bar because I've placed this recursive function of copy nested folder in the separate class named "CopyDir" and all the methods are static as well........so basically there are two classes 1. Form class which contains the progress bar 2. CopyDir class.
what to do so that progress bar keep ticking. Should i pass the progress bar as or the whole form to the CopyDir class??????????????
AAMERSAEED
15-Dec-11 21:11pm
View
Yes now I've got your point completely i'll work on it tomorrow and if any problem occur will get back to you.......Can i have your email id or any contact?...Thanks alot for the time being.-:)
AAMERSAEED
15-Dec-11 16:38pm
View
Yes i've got your point that we get the total bytes but Then how i know about the files that are copied to destination directory i.e how can i get the remaining bytes and keep the progress bar ticking.????????
AAMERSAEED
14-Dec-11 15:46pm
View
Any piece of code because i am a student and in learning process so if you could help me please?
AAMERSAEED
14-Dec-11 15:36pm
View
Actually i want to show a progress bar with a specified percent complete or number of bytes or time remaining?????????????
AAMERSAEED
8-Dec-11 6:23am
View
Below is the code which i have write for XML class:
class ClassXml
{
public static XmlTextWriter textWriter;
public static void create()
{
textWriter = new XmlTextWriter(@"D:\First.xml",Encoding.UTF8);
textWriter.Formatting = Formatting.Indented;
textWriter.WriteStartDocument();
textWriter.WriteComment("Hold data for copyied folders and files");
textWriter.WriteStartElement("Folders");
}
public static void writFile(FileInfo fi,DirectoryInfo diSourceSubDir)
{
textWriter.WriteStartElement("FileName");
textWriter.WriteRaw(fi.Name.ToString());
textWriter.WriteEndElement();
textWriter.WriteStartElement("FileSize");
textWriter.WriteRaw(fi.Length.ToString());
textWriter.WriteEndElement();
textWriter.WriteStartElement("FileCreationTime");
textWriter.WriteRaw(fi.CreationTime.ToLongTimeString());
textWriter.WriteEndElement();
}
public static void writeFolder(DirectoryInfo diSourceSubDir)
{
textWriter.WriteStartElement("FolderName");
textWriter.WriteRaw(diSourceSubDir.Name.ToString());
textWriter.WriteStartElement("FolderCreationTime");
textWriter.WriteRaw(diSourceSubDir.CreationTime.ToLongTimeString());
textWriter.WriteEndElement();
}
}
And the code for copy nested folder's and files from source to destination goes here:
class CopyDir
{
public static void Copy1(string sourceDirectory, string targetDirectory)
{
DirectoryInfo diSource = new DirectoryInfo(sourceDirectory);
DirectoryInfo diTarget = new DirectoryInfo(targetDirectory);
ClassXml.create();
CopyAll(diSource,diTarget);
}
public static void CopyAll(DirectoryInfo source, DirectoryInfo target)
{
if (Directory.Exists(target.FullName) == false)
{
Directory.CreateDirectory(target.FullName);
}
foreach (FileInfo fi in source.GetFiles())
{
fi.CopyTo(Path.Combine(target.ToString(), fi.Name), true);
ClassXml.writFile(fi,source);
}
foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
{
DirectoryInfo nextTargetSubDir = target.CreateSubdirectory(diSourceSubDir.Name);
ClassXml.writeFolder(diSourceSubDir);
CopyAll(diSourceSubDir, nextTargetSubDir);
}
}
public static void GetInfo()
{
ClassXml.textWriter.WriteEndElement();
ClassXml.textWriter.WriteEndElement();
ClassXml.textWriter.WriteEndDocument();
ClassXml.textWriter.Flush();
ClassXml.textWriter.Close();
}
}
AAMERSAEED
5-Dec-11 4:56am
View
But my problem is bit different because i have a code that will copy nested folders and files from source to destination.And i have to maintain the record in xml file that when a folder/file will copied and what was the name of the folder/file....I have done a littile bit by using "XMLTextWriter" class but the problem is that how can i append it when a new file/folder is copied???????????My current is overriding the existing file.........I also tried it by using "XMLDocument" class but i am unable to even write the xml file correctly with it.what should i do??????????Can i post the whole code here?????????Anyone help me please??????????
AAMERSAEED
5-Dec-11 4:56am
View
But my problem is bit different because i have a code that will copy nested folders and files from source to destination.And i have to maintain the record in xml file that when a folder/file will copied and what was the name of the folder/file....I have done a littile bit by using "XMLTextWriter" class but the problem is that how can i append it when a new file/folder is copied???????????My current is overriding the existing file.........I also tried it by using "XMLDocument" class but i am unable to even write the xml file correctly with it.what should i do??????????Can i post the whole code here?????????Anyone help me please??????????
Show More