سلام بر مهندسین گرامی و خیلی تشکر میکنم از پاسختون
دوستان به این روش
private void button1_Click(object sender, EventArgs e)
{
string downloadurl = "";
Version newversion = null;
string xmlurl = "http://x.com/update.xml";
XmlTextReader reader = null;
try
{
reader = new XmlTextReader(xmlurl);
reader.MoveToContent();
string elementname = "";
if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "update"))
{
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
elementname = reader.Name;
}
else
{
if ((reader.NodeType == XmlNodeType.Text) && (reader.HasValue))
{
switch (elementname)
{
case "version":
newversion = new Version(reader.Value);
break;
case "url":
downloadurl = reader.Value;
break;
}
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
//Application.Current.Shutdown();
}
finally
{
if (reader != null)
reader.Close();
}
Version appv = System.Reflection.Assembly.GetExecutingAssembly(). GetName().Version;
if (appv.CompareTo(newversion) < 0)
{
if (MessageBox.Show("آیا فایل آپدیت دانلود شود؟", "سوال", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK)
{
string url = @"http://x.com/x.exe";
WebClient client = new WebClient();
client.DownloadFileCompleted += new AsyncCompletedEventHandler(messageComplete);
if (File.Exists(System.AppDomain.CurrentDomain.BaseDi rectory + @"\x_Backup.exe"))
{
File.Delete(System.AppDomain.CurrentDomain.BaseDir ectory + @"\x_Backup.exe");
File.Move(System.AppDomain.CurrentDomain.BaseDirec tory + @"\x.exe", System.AppDomain.CurrentDomain.BaseDirectory + @"\x_Backup.exe");
}
else
{
File.Move(System.AppDomain.CurrentDomain.BaseDirec tory + @"\x.exe", System.AppDomain.CurrentDomain.BaseDirectory + @"\x_Backup.exe");
}
client.DownloadFileAsync(new Uri(url), System.AppDomain.CurrentDomain.BaseDirectory + @"\x.exe");
MessageBox.Show("فایل در حال دانلود می باشد");
}
else
{
}
}
else
{
MessageBox.Show("این نرم افزار آخرین ورژن موجود می باشد..");
}
}
void messageComplete(object sender, AsyncCompletedEventArgs e)
{
MessageBox.Show("نرم افزار با موفقیت به روز رسانی شد. لطفا نرم افزار را بسته و دوباره باز کنید");
}
}
}
ممنون میشم کدمو تغییر بدید و کمکم کنید
هاست هم خودم دارم
هاست لینوکسی