.NET 4.x Подскажите с кодом по zip (новичек) - C#
Формулировка задачи:
Здравствуйте. Я новичек в C#, не судите строго.
Есть код такой вот:
Код должен считать с web-директории список файлов, найти их на фтп в виде zip с их именем, скачать в папку и разархивировать.
Все бы ничего, но не работает. При попытке проверить получаю:
http://www.cyberforum.ru/attachment....1&d=1457391546
Как исправить, подскажите кто знает. Пожалуйста.
using System;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Net;
namespace ConsoleApplication2
{
class Program
{
private string Directory_game = "";
private string file_exist = "";
private string archive = "";
ZipFile zip;
DirectoryInfo dir;
FileInfo[] files;
WebClient client = new WebClient();
WebClient webClient;
Stopwatch sw = new Stopwatch();
private static int i = 0;
StringBuilder sb;
static void Main(string[] args)
{
string md5s = "";
StringBuilder sb;
string Directory_game = "";
//получаем правильнгую папку
if (Environment.CurrentDirectory[Environment.CurrentDirectory.Length - 1] == '\\')
{
Directory_game = Environment.CurrentDirectory;
}
else
{
Directory_game = Environment.CurrentDirectory + '\\';
}
Console.WriteLine(Directory_game + " <-- папка запуска");
string file_dir = Directory_game;
//получаем список файлов и грузим их
WebClient client = new WebClient();
WebClient Client;
Stream stream = client.OpenRead(@"http://mysite.ru/file/test" + ".ini");
StreamReader sr = new StreamReader(stream);
string newLine;
while ((newLine = sr.ReadLine()) != null) {
Console.WriteLine(" считывается файлик --> " + newLine);
string file_exist;
file_exist = newLine;
if (File.Exists(Directory_game + file_exist))
{
try
{
WebClient webClient = new WebClient();
string slesh = file_exist.Replace(@"", "/");
using (webClient = new WebClient())
{
Uri URL = new Uri("ftp://admin:removed@mail.ru/mods/" + slesh + ".zip");
webClient.DownloadFile(URL, file_dir + file_exist + ".zip");
while (webClient.IsBusy) { }
string fullPath = Path.GetDirectoryName(file_dir + file_exist + ".zip");
try
{
string path = "";
archive = file_dir + file_exist + ".zip";
path = fullPath;
using (zip = new ZipFile(archive, Encoding.UTF32))
{
zip.TempFileFolder = Path.GetTempPath();
zip.ExtractAll(path, ExtractExistingFileAction.OverwriteSilently);
zip = null;
}
path = null;
}
catch { }
try
{
File.Delete(file_dir + file_exist + ".zip");
}
catch {Console.WriteLine("Файл не удален: " + file_dir + file_exist + ".zip"); }
}
Console.WriteLine(" Выполнено успешно! ");
}
catch (Exception mess) { Console.WriteLine("Ошибка: " + mess.Message); };
}
stream.Close();
}
Console.ReadLine();
}
}
}Решение задачи: «.NET 4.x Подскажите с кодом по zip (новичек)»
textual
Листинг программы
ZipFile.ExtractToDirectory(fullPath, Path.GetTempPath(), Encoding.Default);