So what I'm trying to do - download zip file from URI, and extract it into some directory but I'm getting THIS error:
"System.IO.IOException: "The file 'C:\Users\yup_c\source\repos\LauncherYCFPS\bin\Debug\net5.0-windows\new_ver.zip' already exists."
So I think it caused by wc.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFinished);
because it isn't working properly and static void DownloadFinished(object sender, EventArgs e)
launching without waiting file downlod, where am I going wrong?
using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.Data;
using System.Net;
using System.Windows.Forms;
using System.ComponentModel;
namespace LauncherYCFPS
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Button1_Click(object sender, EventArgs e)
{
{
using (WebClient wc = new WebClient())
{
wc.DownloadProgressChanged += wc_DownloadProgressChanged;
wc.DownloadFileAsync(
// Param1 = Link of file
new System.Uri("http://o997388w.beget.tech/new_ver.zip"),
// Param2 = Path to save
@".\new_ver.zip"
) ;
wc.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFinished);
}
static void DownloadFinished(object sender, EventArgs e)
{
string startPath = @".\";
string zipPath = @".\new_ver.zip";
string extractPath = @".\extract";
ZipFile.CreateFromDirectory(startPath, zipPath);
ZipFile.ExtractToDirectory(zipPath, extractPath);
}
}
// Event to track the progress
void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}