0

i'm trying to make an updater that will download from an url with webclient in async mode.

But it cut my download and don't download the full file.

Here's the code :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Diagnostics;

namespace Updater
{
  public partial class Form1 : Form
  {
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        WebClient Client = new WebClient();

        Client.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
        Client.DownloadFileAsync(new Uri("http://localhost/launcher/"), @"C:\launcher.exe");
    }

    private void Completed(object sender, AsyncCompletedEventArgs e)
    {

        if (e.Error != null)
        {
            string error = e.Error.ToString();
            // or
            // error = "Your error message here";

            MessageBox.Show(error);
            return;
        }

        if (e.Cancelled == true)
        {
        }
        else
        {
            Close();
        }

    }
}

}

I'm new with c# and still can't figure where's my error. :/ ty

edit :

I missed to say to download the file launcher.exe at this :

 Client.DownloadFileAsync(new Uri("http://localhost/launcher/"), @"C:\launcher.exe");

to this

 Client.DownloadFileAsync(new Uri("http://localhost/launcher/launcher.exe"), @"C:\launcher.exe");

thanks to Адизбек Эргашев for his links and where it help me : https://stackoverflow.com/a/26232827/6495475

Community
  • 1
  • 1

0 Answers0