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
private string strDestination = @"C:\Program Files\SASystem\SASystem";
private string strSource = @"\\192.192.11.250\ver\IIversion\_New";
delete local file
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
string Current_Version = AssemblyName.GetAssemblyName(strDestination + @"\SASystem.exe").Version.ToString();
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
{
Application.ExitThread();
}
}
else
{
System.Diagnostics.Process.Start(strDestination + @"\SASystem.exe");
Application.ExitThread();
}
copy file
private void copyDirectory(string strSource, string strDestination)
{
bUpdat.Text = "Skip";
int fCount = Directory.GetFiles(strSource, "*.*", SearchOption.AllDirectories).Length;
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!