I have problem when I try to create code for extracting .zip file into a folder, before I show you code, I want to tell you what I need to do?
Its simple, I want to write code so that when a user clicks on a button, it deletes a directory, and then downloads a new .zip file and extracts it at the same directory and name which was deleted... Its something like restoring directory to default form..
I successfully wrote code for deleting the directory and downloading .zip file but I cant write code for extracting that .zip ...
Here is the code
private void button2_Click(object sender, EventArgs e)
{
// Is file downloading yet?
if (webClient != null)
return;
var sprdir = new DirectoryInfo(@"cstrike/sprites");
string sprzippath = @"cstrike/sprites.zip";
string extzippath = @"cstrike";
if (!sprdir.Exists)
{
webClient = new WebClient();
webClient.DownloadFileAsync(new Uri("https://sipi-portfolio.000webhostapp.com/csfiledownload/sprites.zip"), @"cstrike/sprites.zip");
}
else
{
sprdir.Attributes = sprdir.Attributes & ~FileAttributes.ReadOnly;
sprdir.Delete(true);
webClient = new WebClient();
webClient.DownloadFileAsync(new Uri("https://sipi-portfolio.000webhostapp.com/csfiledownload/sprites.zip"), @"cstrike/sprites.zip");
}
}
And yea, I tried with using System.IO
and System.IO.Compress
and ZipFile.ExtractToDirectory
and ExtractToDirectory
, no one working... Just get red line below the text..