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)
{ }