下载rar文件并解压操作

1、下载文件
        public static void downfile()
        {
            WebClient wc = new WebClient();
            wc.DownloadFileCompleted += DownFileComplete;//异步传输完成后调用的方法
            wc.DownloadFileAsync(url,path);
        }

2、下载后对文件进行解压  家业时候自动创建一个与文件夹同目录的同名文件夹,将内容解压到目录中

private static void DownFileComplete(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            string unrarPath = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(path));
            string shellArguments = string.Format("x -o+ \"{0}\" \"{1}\\\"",path, unrarPath);//RAR运行参数请参考帮助文档
            //用Process调用
            using (Process unrar = new Process())
            {
                unrar.Exited += ReadFile;//将文档解压缩后执行ReadFile方法
                unrar.StartInfo.FileName = "WinRAR.exe";//调用WinRAR
                unrar.StartInfo.Arguments = shellArguments;
                //隐藏rar本身的窗口
                unrar.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                unrar.Start();
                //等待解压完成
                unrar.WaitForExit();
                unrar.Close();
            }
        }
3、对文件进行操作
        private static void ReadFile(object sender, EventArgs e)
        { }



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值