Hi guys,
this is my problem, I want to zip a folder that contains several pdf files.
I can do it! Ok, I created a zip that contains my pdf files.
But I found all pdf files corrupted, some files I can open it, but it has white page!
I attach my 2 project: 1st is my little library, 2nd it my test project
Thi is my code,
My little library and test project console:
01.//My method of my little class library02.publicvoidCreateZipToAllFiles(stringparFolderToArchive, 03. stringparZipName, 04. stringparDestinationZipFile)05.{06. LastError = "";07. 08. try09. {10. //Apro lo il canale per la creazione del file zip11. using(Stream stream = File.Open(string.Format(@"{0}\{1}", 12. parDestinationZipFile, 13. parZipName), FileMode.Create))14. {15. //Credo l'archivio logico di compressione16. using(ZipArchive archive = newZipArchive(stream, 17. ZipArchiveMode.Create, false, null))18. {19. //Leggo dalla cartella i file trovati20. foreach(var fileInfo innewDirectoryInfo(parFolderToArchive).GetFiles())21. {22. //Creo un movimento per ogni file trovato23. using(ZipArchiveEntry entry = archive.CreateEntry(fileInfo.Name))24. {25. using(StreamReader sr = newStreamReader(fileInfo.FullName, true))26. {27. //Archivio il file corrente nel file zip28. StreamWriter writer = newStreamWriter(entry.Open());29. 30. while(sr.Peek() >= 0) 31. writer.Write((char)sr.Read());32. 33. writer.Flush();34. }35. }36. }37. }38. }39. }40. catch(Exception ex)41. {42. StringBuilder sb = newStringBuilder("ZipForNav.CreateZipToAllFiles");43. sb.AppendLine(ex.Message);44. 45. if(ex.InnerException!=null)46. {47. sb.AppendLine(ex.InnerException.Message);48. }49. 50. LastError = sb.ToString();51. }52.}53. 54.//Test by project console55.staticvoidMain(string[] args)56.{57. Zip.ZipForNav zip = newZip.ZipForNav();58. zip.CreateZipToAllFiles(@"C:\Temp\Folder to zip", "myzipfile.zip", @"C:\Temp\Destination folder");59. 60. if(zip.LastError != "")61. Console.Write(zip.LastError);62. else63. Console.Write("OK");64. 65. Console.ReadLine();66.}