0

In my application, I need to convert the file which is dropped by user to a ZIP file, in a temporary folder. I am using DotNetZip for this purpose by writing something like this.

zip.AddFile("DroppedFile.xyz");
zip.Save("C:\\Temp\MyZip.zip");

I was able to achieve the same by creating a FileInfo type and using the CopyTo method by writing the below code.

FileInfo myfile = new FileInfo("C:\\DroppedFile.xyz");
myfile.CopyTo("C:\\Temp\MyZip.zip");

I get the same result, both create a ZIP file in the temp directory. But what I want to know is that is there something like I shouldn't use the second approach because I feel it is not being used for its intended purpose (Correct me if I'm wrong). Please let me know the difference between both the approaches.

snippetkid
  • 282
  • 4
  • 16
  • 1
    Have you tried unzipping the file created by the second approach?? – SJuan76 Feb 09 '14 at 11:53
  • 1
    Also, read `FileInfo.CopyTo` documentation. – SJuan76 Feb 09 '14 at 11:55
  • Yeah, I did unzip and it is fine. :) – snippetkid Feb 09 '14 at 11:55
  • Try again. At least the ZIP programs I have refuse to open the "zip file" created with the second method. Also, check the compression rate/file size of the "zip file" created with the second method. Tip: The second method just renames the file; it does not do anything to create an actual ZIP file. – O. R. Mapper Feb 09 '14 at 12:08
  • Tried with WinRar and WinZip, both went fine. Yeah it actually does renaming only. The zip file is exactly of the size of the original file. – snippetkid Feb 09 '14 at 12:48

0 Answers0