[
  {
    "Id": "420494",
    "ThreadId": "205567",
    "Html": "<p>hi,</p>\r\n<p>&nbsp;</p>\r\n<p>i have a little problem with the embedding in c# (c#newbie)</p>\r\n<p>&nbsp;</p>\r\n<p>my code..</p>\r\n<p>&nbsp;</p>\r\n<p>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre><span style=\"color:Blue\">using</span> System;\r\n<span style=\"color:Blue\">using</span> System.Collections.Generic;\r\n<span style=\"color:Blue\">using</span> System.Linq;\r\n<span style=\"color:Blue\">using</span> System.Text;\r\n<span style=\"color:Blue\">using</span> System.Reflection;\r\n<span style=\"color:Blue\">using</span> System.IO;\r\n\r\n<span style=\"color:Blue\">namespace</span> Test<br>{\r\n    <span style=\"color:Blue\">class</span> WebifyChmForm\r\n    {\r\n        <span style=\"color:Blue\">static</span> WebifyChmForm()  \r\n        {\r\n            AppDomain.CurrentDomain.AssemblyResolve += <span style=\"color:Blue\">new</span> ResolveEventHandler(Resolver);\r\n        }\r\n\r\n        <span style=\"color:Blue\">static</span> System.Reflection.Assembly Resolver(<span style=\"color:Blue\">object</span> sender, ResolveEventArgs args)\r\n        {\r\n            Assembly a1 = Assembly.GetExecutingAssembly();\r\n            Stream s = a1.GetManifestResourceStream(<span style=\"color:#A31515\">&quot;Ionic.Zip.dll&quot;</span>);\r\n            <span style=\"color:Blue\">byte</span>[] block = <span style=\"color:Blue\">new</span> <span style=\"color:Blue\">byte</span>[s.Length];\r\n            s.Read(block, 0, block.Length);\r\n            Assembly a2 = Assembly.Load(block);\r\n            <span style=\"color:Blue\">return</span> a2;\r\n        }\r\n\r\n    }\r\n}\r\n<br><br>code in form1 from button<br><br><br><div style=\"color:Black;background-color:White\"><pre> <span style=\"color:Blue\">private</span> <span style=\"color:Blue\">void</span> button1_Click(<span style=\"color:Blue\">object</span> sender, EventArgs e)\r\n        {\r\n\r\n\r\n            <span style=\"color:Blue\">using</span> (ZipFile zip = <span style=\"color:Blue\">new</span> ZipFile())\r\n            {\r\n                \r\n                zip.AddFile(<span style=\"color:#A31515\">&quot;test.png&quot;</span>);\r\n                zip.AddFile(<span style=\"color:#A31515\">&quot;test1.png&quot;</span>);\r\n                zip.Save(<span style=\"color:#A31515\">&quot;myzip.zip&quot;</span>);\r\n            }\r\n\r\n        }\r\n<br><br><span id=\"result_box\"><span style=\"background-color:#ffffff\" title=\"hier kommt ein fehler\">here comes a error</span></span> (bold)<br><br></pre>\r\n</div>\r\n</pre>\r\n</div>\r\n</p>\r\n<pre><pre><span style=\"color:Blue\">using</span> (<span style=\"text-decoration:underline\"><strong>ZipFile</strong></span> zip = <span style=\"color:Blue\">new</span> <span style=\"text-decoration:underline\"><strong>ZipFile</strong></span>())<br><br>error: <span id=\"result_box\"><span title=\"Der Typ- oder  Namespacename &quot;ZipFile&quot; konnte nicht gefunden werden.\">The  type or namespace name &quot;ZipFile&quot; could not be found. </span><span title=\"(Fehlt eine Using-Direktive oder ein Assemblyverweis?)\">(Missing a  using directive or an assembly reference?)<br><br></span></span><span id=\"result_box\"><span style=\"background-color:#ffffff\" title=\"warum funktioniert das nicht?\">why not this work?</span></span><br><br><br>sorry for my bad english..</pre>\r\n</pre>",
    "PostedDate": "2010-03-20T02:05:54.047-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "422644",
    "ThreadId": "205567",
    "Html": "<p>How did you embed the DotNetZip assembly into your EXE?</p>\r\n<p>Depending on how you did that, the name of the embedded stream will vary.&nbsp; It could have the name of your Visual studio project in it:&nbsp; MyProject1.Ionic.Zip.dll . Or it might not.</p>\r\n<p>You can check the names of resources in your assembly by using this kind of code:</p>\r\n<div style=\"border:solid .1em #ccc;color:Black;background-color:White;margin:.25em 0.5em 0 0.5em;padding:0.25em .25em 0.25em .25em\">\r\n<pre>        <span style=\"color:Blue\">public</span> <span style=\"color:Blue\">void</span> Run()\r\n        {\r\n            <span style=\"color:Blue\">var</span> tAssembly = Assembly.LoadFrom(_assemblyName);\r\n\r\n            <span style=\"color:Blue\">string</span>[] resourceNames = tAssembly.GetManifestResourceNames();\r\n            <span style=\"color:Blue\">if</span> (resourceNames != <span style=\"color:Blue\">null</span> &amp;&amp; resourceNames.Length &gt; 0)\r\n            {\r\n\r\n                <span style=\"color:Blue\">foreach</span>(<span style=\"color:Blue\">string</span> resourceName <span style=\"color:Blue\">in</span> resourceNames)\r\n                {\r\n                    System.Console.WriteLine(resourceName);\r\n                }\r\n            }\r\n            <span style=\"color:Blue\">else</span>\r\n            {\r\n                System.Console.WriteLine(<span style=\"color:#A31515\">&quot;-none-&quot;</span>);\r\n            }\r\n        }\r\n\r\n</pre>\r\n</div>\r\n<p>I've written a simple tool that can do this for you, for any .NET assembly. It's available <a href=\"http://cheeso.members.winisp.net/srcview.aspx?dir=Embedded+Resources\">for download</a>.</p>\r\n<p>it looks like this:</p>\r\n<p><img src=\"http://i40.tinypic.com/2ldul3k.jpg\" alt=\"\"></p>",
    "PostedDate": "2010-03-23T09:50:45.08-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "501446",
    "ThreadId": "205567",
    "Html": "<p>Hi ! I have the same problem. When I run your software, I see :&nbsp; &quot;MyProject.Ionic.Zip.dll&quot; !&nbsp; But I do not know how to compile my project without this error:<br><br>error: The&nbsp; type or namespace name &quot;ZipFile&quot; could not be found. (Missing a&nbsp; using directive or an assembly reference?)</p>\r\n<p>I have a warning message :<br><span id=\"result_box\" lang=en><span>Unable to apply the advertisement properties for the element &quot;ionic.zip.dll.MyProject&quot;</span></span></p>\r\n<p>Could you please make a small project (console or window) to compress a file using the included DLL file ?</p>\r\n<p>Thanking you in anticipation !</p>\r\n<p>&nbsp;</p>\r\n<p>It's an example of my project :</p>\r\n<div style=\"color:black;background-color:white;border:1px dashed black\">\r\n<pre><span style=\"color:blue\">using</span> System;\r\n<span style=\"color:blue\">using</span> System.Collections.Generic;\r\n<span style=\"color:blue\">using</span> System.Linq;\r\n<span style=\"color:blue\">using</span> System.Text;\r\n<span style=\"color:blue\">using</span> System.Reflection;\r\n<span style=\"color:green\">//using Ionic.Zip;</span>\r\n<span style=\"color:blue\">using</span> System.IO;\r\n\r\n<span style=\"color:blue\">namespace</span> ConsoleApplication1\r\n{\r\n    <span style=\"color:blue\">class</span> Program\r\n    {\r\n\r\n        <span style=\"color:green\">// static constructor to add a handler to the AssemblyResolve event </span>\r\n        <span style=\"color:blue\">static</span> Program()  <span style=\"color:green\">//   &lt;--- this must be the name of your main class</span>\r\n        {\r\n            AppDomain.CurrentDomain.AssemblyResolve += <span style=\"color:blue\">new</span> ResolveEventHandler(Resolver);\r\n        }\r\n\r\n        <span style=\"color:blue\">static</span> System.Reflection.Assembly Resolver(<span style=\"color:blue\">object</span> sender, ResolveEventArgs args)\r\n        {\r\n            Assembly a1 = Assembly.GetExecutingAssembly();\r\n            System.IO.Stream s = a1.GetManifestResourceStream(<span style=\"color:#a31515\">&quot;Ionic.Zip.dll&quot;</span>);\r\n            <span style=\"color:blue\">byte</span>[] block = <span style=\"color:blue\">new</span> <span style=\"color:blue\">byte</span>[s.Length];\r\n            s.Read(block, 0, block.Length);\r\n            Assembly a2 = Assembly.Load(block);\r\n            <span style=\"color:blue\">return</span> a2;\r\n        }\r\n\r\n\r\n        <span style=\"color:blue\">static</span> <span style=\"color:blue\">void</span> Main(<span style=\"color:blue\">string</span>[] args)\r\n        {\r\n            System.Console.WriteLine(<span style=\"color:#a31515\">&quot;Compressing ...&quot;</span>);<br>&nbsp;           <span style=\"color:blue\">using</span> (<strong><span style=\"color:#ff0000\">ZipFile</span></strong> zip = <span style=\"color:blue\">new</span> <strong><span style=\"color:#ff0000\">ZipFile()</span></strong>)\r\n            {\r\n                zip.AddFile(<span style=\"color:#a31515\">&quot;image.png&quot;</span>);\r\n                zip.Save(<span style=\"color:#a31515\">&quot;image_compressed.zip&quot;</span>);\r\n            }\r\n            \r\n            System.Console.Write(<span style=\"color:#a31515\">&quot;End !&quot;</span>);\r\n            System.Console.ReadLine();\r\n        }<br>&nbsp;    }\r\n}\r\n</pre>\r\n</div>\r\n<p>Help me please <img src=\"http://www.ecplusplus.com/gfx/smiley_sad.gif\" border=0 alt=\"\"> !</p>",
    "PostedDate": "2010-10-02T07:58:38.027-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "502432",
    "ThreadId": "205567",
    "Html": "No, I don't believe you are having the same problem. I think you are trying to do the same thing, or a similar thing, which is to embed the dll into your exe, but i don't think you are having the same problem. \r\n<br><br>\r\nI think you have a more basic problem:  <i>The ZipFile type is not known to the compiler.</i>  The first question, is, of course, why did you comment out the namespace declaration at the top of your source code?  The line that reads &quot;using Ionic.Zip&quot; is the line that declares the ZipFile type (as well as all the others in the Ionic.Zip namespace) to the compiler.  If you comment out that line, you will get unknown type errors at compile time. \r\n<br><br>\r\n\r\nI think the error message you posted must be a translation, because it doesn't sound familiar to me. But I'm pretty sure you need to include the namespace declaration in order to successfully compile.  Embedding the dll allows you to avoid distributing the dll separately at runtime; it does not change the compile-time requirements for namespace declaration, and assembly references.\r\n<br><br>\r\nGood luck.\r\n",
    "PostedDate": "2010-10-05T05:10:49.407-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "502564",
    "ThreadId": "205567",
    "Html": "<p>Hi,</p>\r\n<p><br>Thank you for your response and your time given to my problem.</p>\r\n<p>So, yes I translated my error generated by Visual Studio, it was a temporary warning message.As the title of this post, I try to embed the DLL in my project but I can not.<br> As the example above,&nbsp; there haven't&nbsp; &quot;using Ionic.Zip&quot;, so I put the line a comment. Now I understand that it is important to put this line for compiler.<br><br>I give you my source file if you have time to find and solve my problem, I'd be very grateful for some help.</p>\r\n<p><a href=\"http://ReRRemi.fr/EmbeddedDLL.zip\">My Embedded DLL Test Project :)</a></p>",
    "PostedDate": "2010-10-05T09:07:20.09-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "502974",
    "ThreadId": "205567",
    "Html": "Sorry, I don't have a computer with Visual Studio available to me at the moment, so I cannot do this for you. I CAN advise you, though. <br><br>\r\n\r\nAt this point, I don't know the problem we're trying to solve.",
    "PostedDate": "2010-10-06T06:39:57.157-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "562354",
    "ThreadId": "205567",
    "Html": "\r\n<p>I made a class file that you can copy paste into your project and use it to call the basic Zip and Unzip Methods using the Ionic.Zip.Reduced.dll.&nbsp;</p>\r\n<p>All that is needed is that you include Ionic.Zip.Reduced.dll into your project and you set it as an embedded resource.&nbsp; Then just add this code into your project.</p>\r\n<p>And from your calling class, you can just call ZIPPER.CreateZipFile(zipfileName, datafileName) and ZIPPER.UnzipFile(zipfilename, unzipFileLocation).&nbsp; If you need</p>\r\n<p>any other methods from the DLL, you should be able to follow the code fairly easily (it's commented) to implement whatever methods you were looking for.</p>\r\n<pre>using System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Text;\r\n\r\nnamespace ZIPPER\r\n{\r\n   public static class ZipReflection\r\n    {\r\n        public static string ErrorMessage { get; set; }\r\n\r\n        public static bool CreateZipFile(string zipFileName, string dataFileName)\r\n        {\r\n            try\r\n            {\r\n                ErrorMessage = string.Empty;\r\n\r\n                //Get the name of the current executing assembly\r\n                string assemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;\r\n\r\n                //Specify the embedded resource DLL\r\n                string dllName = &quot;Ionic.Zip.Reduced.dll&quot;;\r\n\r\n                //Build complete embedded resource name\r\n                string embeddedResourceName = assemblyName &#43; &quot;.&quot; &#43; dllName;\r\n\r\n                //Retrieve the embedded DLL as a stream and then convert that stream into a byte array\r\n                System.IO.Stream objStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedResourceName);\r\n                byte[] rawBytes = new byte[objStream.Length];\r\n                objStream.Read(rawBytes, 0, System.Convert.ToInt32(objStream.Length));\r\n                objStream.Close();\r\n\r\n                //Load the embedded DLL as an assembly by passing the byte array into the Load method\r\n                System.Reflection.Assembly assembly = System.AppDomain.CurrentDomain.Load(rawBytes);\r\n\r\n                //Retrieve the ZipFile type from assembly and create a new instance of it\r\n                Type zipFileType = assembly.GetType(&quot;Ionic.Zip.ZipFile&quot;);\r\n                object zipFileObject = Activator.CreateInstance(zipFileType);\r\n\r\n                //Create object array of parameters to be sent to reflected method\r\n                object[] methodParams = { dataFileName, string.Empty };\r\n\r\n                //Invoke the AddFile method on the zipFileObject and pass in parameter array\r\n                zipFileType.InvokeMember(&quot;AddFile&quot;, System.Reflection.BindingFlags.InvokeMethod, null, zipFileObject, methodParams);\r\n\r\n                //Create object array of parameters to be sent to reflected method\r\n                methodParams = new object[] { zipFileName };\r\n\r\n                //Invoke the Save method on the zipFileObject and pass in parameter array\r\n                zipFileType.InvokeMember(&quot;Save&quot;, System.Reflection.BindingFlags.InvokeMethod, null, zipFileObject, methodParams);\r\n\r\n                //Invoke the Dispose method clean up any used resources\r\n                zipFileType.InvokeMember(&quot;Dispose&quot;, System.Reflection.BindingFlags.InvokeMethod, null, zipFileObject, null);\r\n\r\n                return true;\r\n            }\r\n            catch (Exception ex)\r\n            {\r\n                ErrorMessage = ex.Message;\r\n                if (ex.InnerException != null)\r\n                    ErrorMessage = ErrorMessage &#43; System.Environment.NewLine &#43; ex.InnerException.Message;\r\n                return false;\r\n            }\r\n        }\r\n\r\n        public static bool UnzipFile(string zipFileName, string unzipFileLocation)\r\n        {\r\n            try\r\n            {\r\n                ErrorMessage = string.Empty;\r\n\r\n                //Get the name of the current executing assembly\r\n                string assemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;\r\n\r\n                //Specify the embedded resource DLL\r\n                string dllName = &quot;Ionic.Zip.Reduced.dll&quot;;\r\n\r\n                //Build complete embedded resource name\r\n                string embeddedResourceName = assemblyName &#43; &quot;.&quot; &#43; dllName;\r\n\r\n                //Retrieve the embedded DLL as a stream and then convert that stream into a byte array\r\n                System.IO.Stream objStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedResourceName);\r\n                byte[] rawBytes = new byte[objStream.Length];\r\n                objStream.Read(rawBytes, 0, System.Convert.ToInt32(objStream.Length));\r\n                objStream.Close();\r\n\r\n                //Load the embedded DLL as an assembly by passing the byte array into the Load method\r\n                System.Reflection.Assembly assembly = System.AppDomain.CurrentDomain.Load(rawBytes);\r\n\r\n                //Retrieve the ZipFile type from assembly and create a new instance of it\r\n                Type zipFileType = assembly.GetType(&quot;Ionic.Zip.ZipFile&quot;);\r\n                object zipFileObject = Activator.CreateInstance(zipFileType);\r\n\r\n                //Retrieve the ExtractExistingFileAction enumeration type from assembly\r\n                Type zipEnumerationType = assembly.GetType(&quot;Ionic.Zip.ExtractExistingFileAction&quot;);\r\n\r\n                //Retrieve specific enums from zipEnumeration and get its value\r\n                System.Reflection.FieldInfo zipEnum1 = zipEnumerationType.GetField(&quot;OverwriteSilently&quot;);\r\n                //System.Reflection.FieldInfo zipEnum2 = zipEnumerationType.GetField(&quot;DoNotOverwrite&quot;);\r\n                //System.Reflection.FieldInfo zipEnum3 = zipEnumerationType.GetField(&quot;InvokeExtractProgressEvent&quot;);\r\n                //System.Reflection.FieldInfo zipEnum4 = zipEnumerationType.GetField(&quot;Throw&quot;);\r\n                //int enumValue = (int)zipEnum1.GetValue(zipEnumerationType);\r\n                //object newEnum = Enum.ToObject(zipEnumerationType, enumValue);\r\n                object enumValue = zipEnum1.GetValue(zipEnumerationType);\r\n\r\n                //Create object array of parameters to be sent to reflected method\r\n                object[] methodParams = { zipFileName };\r\n\r\n                //Invoke the Read method on the zipFileObject and pass in parameter array \r\n                //Return the result back into the zipFileObject  [ie. Zip MyZip.Read()]\r\n                zipFileObject = zipFileType.InvokeMember(&quot;Read&quot;, System.Reflection.BindingFlags.InvokeMethod, null, zipFileObject, methodParams);\r\n\r\n                //Create object array of parameters to be sent to reflected method\r\n                methodParams = new object[] { unzipFileLocation, enumValue };\r\n\r\n                //Invoke the ExtractAll method on the zipFileObject and pass in parameter array \r\n                zipFileType.InvokeMember(&quot;ExtractAll&quot;, System.Reflection.BindingFlags.InvokeMethod, null, zipFileObject, methodParams);\r\n\r\n                //Invoke the Dispose method so connection to the Zipfile is released so the file can be deleted\r\n                zipFileType.InvokeMember(&quot;Dispose&quot;, System.Reflection.BindingFlags.InvokeMethod, null, zipFileObject, null);\r\n                \r\n                return true;\r\n\r\n            }\r\n            catch (Exception ex)\r\n            {\r\n                ErrorMessage = ex.Message;\r\n                if (ex.InnerException != null)\r\n                    ErrorMessage = ErrorMessage &#43; System.Environment.NewLine &#43; ex.InnerException.Message;\r\n                return false;\r\n            }\r\n        }\r\n    }\r\n}\r\n</pre>\r\n",
    "PostedDate": "2011-02-07T19:57:46.71-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "569491",
    "ThreadId": "205567",
    "Html": "<p>Thanks <span class=\"UserProfileLink\">Simcoder</span>,</p>\r\n<p>I despaired at not finding a solution !</p>\r\n<p>I no longer work on the project that uses DotNetZip but it's interest for another new project, so thank you very much !</p>",
    "PostedDate": "2011-02-21T01:59:22.36-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]