title: C#.net identify zip file
body: <p>I am currently using the SharpZip api to handle my zip file entries. It works splendid for zipping and unzipping. Though, I am having trouble identifying if a file is a zip or not. I need to know if there is a way to detect if a file stream can be decompressed. Originally I used  </p>
  
  <pre><code>FileStream lFileStreamIn = File.OpenRead(mSourceFile);
  lZipFile = new ZipFile(lFileStreamIn);
  ZipInputStream lZipStreamTester = new ZipInputStream(lFileStreamIn, mBufferSize);// not working
  lZipStreamTester.Read(lBuffer, 0, 0);
  if (lZipStreamTester.CanDecompressEntry)
  {
  </code></pre>
  
  <p>The LZipStreamTester becomes null every time and the if statement fails. I tried it with/without a buffer. Can anybody give any insight as to why? I am aware that i can check for file extension. I need something that is more definitive than that. I am also aware that zip has a magic #(PK something), but it isn't a guarantee that it will always be there because it isn't a requirement of the format.</p>
  
  <p>Also i read about .net 4.5 having native zip support so my project may migrate to that instead of sharpzip but I still need didn't see a method/param similar to CanDecompressEntry here: <a href="http://msdn.microsoft.com/en-us/library/3z72378a%28v=vs.110%29">http://msdn.microsoft.com/en-us/library/3z72378a%28v=vs.110%29</a></p>
  
  <p>My last resort will be to use a try catch and attempt an unzip on the file.</p>