Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From <a href="http://blogs.msdn.com/msdnmagazine/archive/2007/05/16/2675596.aspx" rel="noreferrer">MSDN</a>, </p> <p>In this sample, the Package class is used (as opposed to the ZipPackage.) Having worked with both, I've only seen flakiness happen when there's corruption in the zip file. Not necessarily corruption that throws the Windows extractor or Winzip, but something that the Packaging components have trouble handling.</p> <p>Hope this helps, maybe it can provide you an alternative to debugging the issue.</p> <pre><code>using System; using System.IO; using System.IO.Packaging; using System.Text; class ExtractPackagedImages { static void Main(string[] paths) { foreach (string path in paths) { using (Package package = Package.Open( path, FileMode.Open, FileAccess.Read)) { DirectoryInfo dir = Directory.CreateDirectory(path + " Images"); foreach (PackagePart part in package.GetParts()) { if (part.ContentType.ToLowerInvariant().StartsWith("image/")) { string target = Path.Combine( dir.FullName, CreateFilenameFromUri(part.Uri)); using (Stream source = part.GetStream( FileMode.Open, FileAccess.Read)) using (Stream destination = File.OpenWrite(target)) { byte[] buffer = new byte[0x1000]; int read; while ((read = source.Read(buffer, 0, buffer.Length)) &gt; 0) { destination.Write(buffer, 0, read); } } Console.WriteLine("Extracted {0}", target); } } } } Console.WriteLine("Done"); } private static string CreateFilenameFromUri(Uri uri) { char [] invalidChars = Path.GetInvalidFileNameChars(); StringBuilder sb = new StringBuilder(uri.OriginalString.Length); foreach (char c in uri.OriginalString) { sb.Append(Array.IndexOf(invalidChars, c) &lt; 0 ? c : '_'); } return sb.ToString(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload