Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi..

Following is my code:-

C#
public static void Sync(string sourcePath, string destinationPath)
       {
           bool dirExisted = DirExists(destinationPath);

           //get the source files
           string[] srcFiles = Directory.GetFiles(sourcePath);

           foreach (string sourceFile in srcFiles)
           {
               FileInfo sourceInfo = new FileInfo(sourceFile);
               string destFile = Path.Combine(destinationPath, sourceInfo.Name);

               if (!dirExisted && File.Exists(destFile))
               {
                   FileInfo destInfo = new FileInfo(destFile);
                   if (sourceInfo.LastWriteTime > destInfo.LastWriteTime)
                   {
                       //file is newer, so copy it
                       File.Copy(sourceFile, Path.Combine(destinationPath, sourceInfo.Name), true);

                      MessageBox.Show(sourceFile + "copied(newer version)");




                   }
               }

               else
               {
                   File.Copy(sourceFile,Path.Combine(destinationPath,sourceInfo.Name));
                   MessageBox.Show(sourceFile + "copied");
               }
           }

           DeleteOldDestinationFiles(srcFiles, destinationPath);

           //now process the directories if exist
           string[] dirs = Directory.GetDirectories(sourcePath);

           foreach (string dir in dirs)
           {
               DirectoryInfo dirInfo = new DirectoryInfo(dir);

               //recursive do the directories
               Sync(dir, Path.Combine(destinationPath, dirInfo.Name));
           }
       }

here instead of MessageBoxes i want to use ToolStripStatus Label..

can anyone help me with this??

Thanks..
Posted
Updated 7-Dec-11 20:47pm
v2
Comments
uspatel 8-Dec-11 2:47am    
[EDIT]:"pre" tag added

1 solution

Try:
C#
myStatus.Text = sourceFile + "copied";
Only I would include a space in front of the word copied


"I get the following error :- An object reference is required for the non-static field, method, or property 'SplashScreen.Form1.toolStripStatusLabel1'"

OK. This isn't going to be easy to explain...

You are trying to access a generic Label, instead of a specific label, so it is complaining that you need an object reference. Why? Because your method is declared as static so it does not have a this reference. If you use a static method, it can only access it's parameters and static parts of the containing class - it can't access "normal" instance values.

It's a bit like putting your phone in your car glove box, and then expecting to find it in any car glove box you try to open. It doesn't happen - you have to refer to the specific instance of a car that you put the phone in to retrieve it.

Remove the static declaration from your method, and it should work.
 
Share this answer
 
v2
Comments
bhagyap 8-Dec-11 3:09am    
I tried but unable to achieve..
bhagyap 8-Dec-11 3:10am    
thing is i am unable to access my toolstripstatuslabel here..
OriginalGriff 8-Dec-11 3:38am    
Why? What happens when you try? How are you accessing it? When are you accessing it?
bhagyap 8-Dec-11 3:54am    
I get the following error :- An object reference is required for the non-static field, method, or property 'SplashScreen.Form1.toolStripStatusLabel1'
OriginalGriff 8-Dec-11 4:02am    
Answer updated

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900