C# otomatik dosya indirme

BugraSahinn

Hectopat
Katılım
21 Kasım 2018
Mesajlar
52
Aşağıdaki kodda güncellemek istediklerini soruyor evet derlerse dosya güncellemesi yapması gerekiyor aşağıdaki kodda bulunan (//) güncelleme komutunu yapamadım.
Uygulamanın bulunduğu konuma yüklemek gerekiyor.
Var olan dosya ile değiştirmek gerekiyor mesela uygulamayı çalıştırdığımız exe, deneme.exe evet dedikleri zaman deneme.exe download URL'deki internet sayfasından(sayfadaki de deneme.exe) otomatik üzere inip deneme.exe'nin üstüne yazılması gerek.

C#:
string str = String.Format("Yeni sürüm mevcut!\nSizin sürümünüz: {0}.nYeni sürüm: {1}. ", applicationVersion, newVersion, aboutUpdate);

if (DialogResult.No != MessageBox.Show(str + "\nGüncellemeyi indirmek ister misiniz?", "Güncellemeyi kontrol et", MessageBoxButtons.YesNo, MessageBoxIcon.Question))

{

try

{

//string W_dosya = Application.ExecutablePath;

//WebClient W_Client = new WebClient();

//W_Client.DownloadFile(downloadURL, W_dosya);



}

catch { }

return;

Şimdiden teşekkürler.
 
Son düzenleyen: Moderatör:
Çözüm olarak böyle bir yol seçtim umarım işinize yarar. Genellikle güncelleme işlemleri başka bir program (arkaplanda çalışabilecek) ya da bir servis aracılığıyla yapılır ben cmd kullanarak biraz daha pratik ve kolay bir çözüm getirdim.

C#:
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Net;
using System.Diagnostics;
using System.Text;
namespace Update_App
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            CheckForIllegalCrossThreadCalls = false;
            InitializeComponent();
        }
        private string applicationVersion = "", newVersion = "", aboutUpdate = "";
        private string downloadURL = "DownloadURL";
        private string W_dosya = Application.StartupPath + @"\update_001";
        private void Button1_Click(object sender, EventArgs e)
        {
            string str = String.Format("Yeni sürüm mevcut!\nSizin sürümünüz: {0}.nYeni sürüm: {1}. ", applicationVersion, newVersion, aboutUpdate);

            if (DialogResult.No != MessageBox.Show(str + "\nGüncellemeyi indirmek ister misiniz?", "Güncellemeyi kontrol et", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
            {
                try
                {
                    
                    WebClient W_Client = new WebClient();
                    W_Client.DownloadFileCompleted += W_Client_DownloadFileCompleted;
                    W_Client.DownloadFileAsync(new Uri(downloadURL), W_dosya);
                }

                catch (Exception ex) { MessageBox.Show(ex.Message); }

            }
        }

        private void W_Client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            //İNDİRME BİTİNCEKİ İŞLEMLER
            UpdateAPP();
        }

        private void Button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show(Application.ExecutablePath);
        }

        private void UpdateAPP()
        {
            string mainPath = Application.ExecutablePath;
            Process process = new Process();
            ProcessStartInfo info = new ProcessStartInfo();
            info.FileName = "cmd.exe";
            info.UseShellExecute = false;
            info.CreateNoWindow = true;
            info.Arguments = "/C TIMEOUT /T 2&DEL " + mainPath + "&MOVE " + W_dosya + "," + mainPath + "&START " + mainPath;
            process.StartInfo = info;
            process.Start();
            Application.Exit();
        }
    }
}
 
Uyarı! Bu konu 5 yıl önce açıldı.
Muhtemelen daha fazla tartışma gerekli değildir ki bu durumda yeni bir konu başlatmayı öneririz. Eğer yine de cevabınızın gerekli olduğunu düşünüyorsanız buna rağmen cevap verebilirsiniz.

Geri
Yukarı