C# 如何下载和解压C语言中的程序#

C# 如何下载和解压C语言中的程序#,c#,winforms,C#,Winforms,我正在为游戏服务器制作发射器。我怎样才能让游戏下载和解压呢。我有一个zip文件,我准备,我希望它下载并安装“C:\ProgramFiles”自动 using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using

我正在为游戏服务器制作发射器。我怎样才能让游戏下载和解压呢。我有一个zip文件,我准备,我希望它下载并安装“C:\ProgramFiles”自动

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;

namespace WindowsFormsApp3
{
    public partial class Form1 : Form
    {

        WebClient web = new WebClient();

        public Form1()
        {
            InitializeComponent();
        }

        private void DosyaIndirmeTamamlandiUyarisi(object sender, AsyncCompletedEventArgs e)
        {
            MessageBox.Show("Download Completed");
        }

        private void Download_Click(object sender, EventArgs e)
        {
            web.DownloadFileCompleted += new AsyncCompletedEventHandler(DosyaIndirmeTamamlandiUyarisi);

            Uri DosyaAdresi = new Uri(textBox1.Text);
            web.DownloadFileAsync(DosyaAdresi, textBox1.Text.Length.ToString()+".zip");
        }
    }
}

解压文件。 将async和Wait添加到代码中

更改为您自己的设置

公共部分类表单1:表单
{
私人网络客户端(网络客户端);;
公共表格1()
{
初始化组件();
_webClient=新的webClient();
}
私有异步无效下载\u单击(对象发送方,事件参数e)
{
Uri dosyaandresi=新Uri(@“https://zaycev.net/download/packie/ae4cce5699f15a877ff42559b5a2555d/9443");
var fileName=“下载”;
wait_webClient.DownloadFileTaskAsync(dosyaandresi,fileName+“.zip”);
DirectoryInfo unZipDir=新的DirectoryInfo(“解压”);
如果(!unZipDir.Exists)
{
unZipDir.Create();
}
ZipFile.ExtractToDirectory(文件名+“.zip”,解压zipdir.FullName);
}

您正在处理的是哪一部分?看起来您成功下载了该文件。请参阅第二个任务。另外,请注意,要访问
%ProgramFiles%
文件夹,您需要提升您的进程(也称为以管理员身份运行)。我这样试过,但没有解压缩。pastecode.io/s/1hija2BtUuI这样试过,但没有解压缩。@YavuzAdem解压到文件夹。我更新了答案@DirectoryInfo unZipDir=new DirectoryInfo(“解压”);指定您的目录,而不是解压。