.NET 4.x Подскажите с кодом по zip (новичек) - C#

Узнай цену своей работы

Формулировка задачи:

Здравствуйте. Я новичек в C#, не судите строго. Есть код такой вот:
Листинг программы
  1. using System;
  2. using System.Text;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.IO.Compression;
  6. using System.Net;
  7.  
  8. namespace ConsoleApplication2
  9. {
  10. class Program
  11. {
  12. private string Directory_game = "";
  13. private string file_exist = "";
  14. private string archive = "";
  15. ZipFile zip;
  16. DirectoryInfo dir;
  17. FileInfo[] files;
  18. WebClient client = new WebClient();
  19. WebClient webClient;
  20. Stopwatch sw = new Stopwatch();
  21. private static int i = 0;
  22. StringBuilder sb;
  23. static void Main(string[] args)
  24. {
  25. string md5s = "";
  26. StringBuilder sb;
  27. string Directory_game = "";
  28. //получаем правильнгую папку
  29. if (Environment.CurrentDirectory[Environment.CurrentDirectory.Length - 1] == '\\')
  30. {
  31. Directory_game = Environment.CurrentDirectory;
  32. }
  33. else
  34. {
  35. Directory_game = Environment.CurrentDirectory + '\\';
  36. }
  37. Console.WriteLine(Directory_game + " <-- папка запуска");
  38. string file_dir = Directory_game;
  39. //получаем список файлов и грузим их
  40. WebClient client = new WebClient();
  41. WebClient Client;
  42. Stream stream = client.OpenRead(@"http://mysite.ru/file/test" + ".ini");
  43. StreamReader sr = new StreamReader(stream);
  44. string newLine;
  45. while ((newLine = sr.ReadLine()) != null) {
  46. Console.WriteLine(" считывается файлик --> " + newLine);
  47. string file_exist;
  48. file_exist = newLine;
  49. if (File.Exists(Directory_game + file_exist))
  50. {
  51. try
  52. {
  53. WebClient webClient = new WebClient();
  54. string slesh = file_exist.Replace(@"", "/");
  55. using (webClient = new WebClient())
  56. {
  57. Uri URL = new Uri("ftp://admin:removed@mail.ru/mods/" + slesh + ".zip");
  58. webClient.DownloadFile(URL, file_dir + file_exist + ".zip");
  59. while (webClient.IsBusy) { }
  60. string fullPath = Path.GetDirectoryName(file_dir + file_exist + ".zip");
  61. try
  62. {
  63. string path = "";
  64. archive = file_dir + file_exist + ".zip";
  65. path = fullPath;
  66. using (zip = new ZipFile(archive, Encoding.UTF32))
  67. {
  68. zip.TempFileFolder = Path.GetTempPath();
  69. zip.ExtractAll(path, ExtractExistingFileAction.OverwriteSilently);
  70. zip = null;
  71. }
  72. path = null;
  73. }
  74. catch { }
  75. try
  76. {
  77. File.Delete(file_dir + file_exist + ".zip");
  78. }
  79. catch {Console.WriteLine("Файл не удален: " + file_dir + file_exist + ".zip"); }
  80. }
  81. Console.WriteLine(" Выполнено успешно! ");
  82. }
  83. catch (Exception mess) { Console.WriteLine("Ошибка: " + mess.Message); };
  84. }
  85. stream.Close();
  86. }
  87. Console.ReadLine();
  88. }
  89. }
  90. }
Код должен считать с web-директории список файлов, найти их на фтп в виде zip с их именем, скачать в папку и разархивировать. Все бы ничего, но не работает. При попытке проверить получаю: http://www.cyberforum.ru/attachment....1&d=1457391546 Как исправить, подскажите кто знает. Пожалуйста.

Решение задачи: «.NET 4.x Подскажите с кодом по zip (новичек)»

textual
Листинг программы
  1. ZipFile.ExtractToDirectory(fullPath, Path.GetTempPath(), Encoding.Default);

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

15   голосов , оценка 3.867 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы