soleimani.em
پنج شنبه 28 فروردین 1393, 13:52 عصر
سلام به دوستان من از این کد برای چک کردن و کپی کردن فایل های موجود در پوشه شیر شده در شبکه محلی استفاده کردم منتها یه مشکلی دارم برای احراز هویت که کامپیوتری که اطلاعات روش هست یوزر و پسورد میخاد.
دوستان اگه راهنماییم کنید یا کدها رو برام اصلاح کنید ممنون میشم
آدرس ها
private string strDestination = @"C:\Program Files\SASystem\SASystem";
private string strSource = @"\\192.192.11.250\ver\IIversion\_New";
حذف فایلهای قدیمی سیستم
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 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();
}
کپی کردن فایل ها از شبکه نیاز به احراز هویت
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 ";
}
دوستان اگه راهنماییم کنید یا کدها رو برام اصلاح کنید ممنون میشم
آدرس ها
private string strDestination = @"C:\Program Files\SASystem\SASystem";
private string strSource = @"\\192.192.11.250\ver\IIversion\_New";
حذف فایلهای قدیمی سیستم
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 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();
}
کپی کردن فایل ها از شبکه نیاز به احراز هویت
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 ";
}