Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I need to check text file from other computer system file that is sharing on network, and copy some file from network system to local.

I use this code

C#
private string strDestination = @"C:\Program Files\SASystem\SASystem";
private string strSource = @"\\192.192.11.250\ver\IIversion\_New";


delete local file
C#
private void DeleteFilesFromDirectory(string directoryPath)
       {
           DirectoryInfo d = new DirectoryInfo(directoryPath);
           foreach (FileInfo fi in d.GetFiles())
           {
               fi.Delete();
           }
           foreach (DirectoryInfo di in d.GetDirectories())
           {
               DeleteFilesFromDirectory(di.FullName);
               di.Delete();
           }
       }

check txt file
C#
//Check Current Version
            string Current_Version = AssemblyName.GetAssemblyName(strDestination + @"\SASystem.exe").Version.ToString();
            //Check New Version
            StreamReader wr = File.OpenText(@"\\192.192.11.250\ver\IIversion\New_Version.txt");
            string New_version = wr.ReadToEnd();
            wr.Close();
            int Current = Convert.ToInt32(Current_Version.Replace(".", ""));
            int New = Convert.ToInt32(New_version.Replace(".", ""));
            if (New > Current)
            {
                if (MessageBox.Show("New version is available on server, Do you want to Upgrade current Version? ", "New Version", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    this.Opacity = 100;
                }
                else
                {
                    //System.Diagnostics.Process.Start(strDestination + @"\SASystem.exe");
                    Application.ExitThread();
                }
            }
            else
            {
                System.Diagnostics.Process.Start(strDestination + @"\SASystem.exe");
                Application.ExitThread();
            }

copy file
C#
private void copyDirectory(string strSource, string strDestination)
       {
           bUpdat.Text = "Skip";
           // searches current directory and sub directory
           int fCount = Directory.GetFiles(strSource, "*.*", SearchOption.AllDirectories).Length;
           // MessageBox.Show(fCount+"");
           progressBar1.Maximum = fCount;

           if (!Directory.Exists(strDestination))
           {
               Directory.CreateDirectory(strDestination);
           }
           DirectoryInfo dirInfo = new DirectoryInfo(strSource);
           FileInfo[] files = dirInfo.GetFiles();
           foreach (FileInfo tempfile in files)
           {
               Application.DoEvents();
               if (bUpdat.Text == "Skip")
               {
                   progressBar1.PerformStep();
                   tempfile.CopyTo(Path.Combine(strDestination, tempfile.Name));
               }
               Application.DoEvents();
           }
           DirectoryInfo[] dirctororys = dirInfo.GetDirectories();
           foreach (DirectoryInfo tempdir in dirctororys)
           {
               if (bUpdat.Text == "Skip")
               {
                   copyDirectory(Path.Combine(strSource, tempdir.Name), Path.Combine(strDestination, tempdir.Name));
               }
               Application.DoEvents();
           }

           progressBar1.Value = 0;
           bUpdat.Text = "Upgrade ";

       }


Is there anyone help me to modify this code? thanks for attention!
Posted
Updated 16-Apr-14 22:32pm
v3

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