[
  {
    "Id": "520682",
    "ThreadId": "234342",
    "Html": "\r\n<p>Hi,</p>\r\n<p>First of all thank you for your fine library !</p>\r\n<p>i have been trying to do the following:</p>\r\n<p>using a vb.net 4.0 webapp</p>\r\n<p>the DotNetZipLib-DevKit-v1.9 DLL</p>\r\n<p>- on the server side, loop through a list of file names on the server, add them to a zip file and output a selfextractor .exe file for a user to download the file to his local drive and extract it.</p>\r\n<p>i have tried collecting all kinds of examples of code to achieve this, using this method, i can download archive.exe but when i try to open it on vista (as administrator) i get this error:</p>\r\n<p>16 bit MS-DOS Subsystem</p>\r\n<p>&quot;The NTVDM CPU has encountered an illegal instruction.</p>\r\n<p>CS:127c IP:09ee OP:63 32 6c 30 5a Choose 'close' to terminate the application&quot;</p>\r\n<p>if i click ignore then the command window just stays open and nothing happens.</p>\r\n<p>can you try and help ? thanks</p>\r\n<p>&nbsp;</p>\r\n<p>here is the code i use:</p>\r\n<p></p>\r\n<div style=\"color:black; background-color:white\">\r\n<pre>\r\n    <span style=\"color:blue\">Protected</span> <span style=\"color:blue\">Sub</span> Download1_Click(<span style=\"color:blue\">ByVal</span> sender <span style=\"color:blue\">As</span> <span style=\"color:blue\">Object</span>, <span style=\"color:blue\">ByVal</span> e <span style=\"color:blue\">As</span> EventArgs) <span style=\"color:blue\">Handles</span> Download1.Click\r\n        <span style=\"color:blue\">Try</span>\r\n\r\n            <span style=\"color:blue\">Dim</span> emptyCheckboxList <span style=\"color:blue\">As</span> <span style=\"color:blue\">Boolean</span> = <span style=\"color:blue\">False</span>\r\n            <span style=\"color:blue\">Dim</span> ItemsNum <span style=\"color:blue\">As</span> Int32 = chklst.Items.<span style=\"color:blue\">Count</span>()\r\n\r\n            Response.Clear()\r\n            Response.BufferOutput = <span style=\"color:blue\">False</span>\r\n\r\n            Response.AddHeader(<span style=\"color:#a31515\">&quot;Content-disposition&quot;</span>, <span style=\"color:#a31515\">&quot;attachment; filename=&quot;</span> &#43; <span style=\"color:#a31515\">&quot;archive.exe&quot;</span>)\r\n            Response.AddHeader(<span style=\"color:#a31515\">&quot;Content-Description&quot;</span>, <span style=\"color:#a31515\">&quot;File Transfer&quot;</span>)\r\n            Response.AddHeader(<span style=\"color:#a31515\">&quot;Content-Transfer-Encoding&quot;</span>, <span style=\"color:#a31515\">&quot;binary&quot;</span>)\r\n            Response.ContentType = <span style=\"color:#a31515\">&quot;application/exe&quot;</span>\r\n\r\n            <span style=\"color:blue\">Using</span> zip <span style=\"color:blue\">As</span> <span style=\"color:blue\">New</span> ZipFile()\r\n\r\n                <span style=\"color:blue\">For</span> <span style=\"color:blue\">Each</span> lstItem <span style=\"color:blue\">In</span> chklst.Items\r\n\r\n                    <span style=\"color:blue\">If</span> lstItem.Selected = <span style=\"color:blue\">True</span> <span style=\"color:blue\">Then</span>\r\n                        emptyCheckboxList = <span style=\"color:blue\">True</span>\r\n                        debug1.Text = debug1.Text &amp; <span style=\"color:#a31515\">&quot;downloaded: &quot;</span> &amp; lstItem.ToString &amp; <span style=\"color:#a31515\">&quot;&lt;br /&gt;&quot;</span>\r\n                        zip.AddFile(lstItem.ToString, <span style=\"color:#a31515\">&quot;&quot;</span>)\r\n                    <span style=\"color:blue\">End</span> <span style=\"color:blue\">If</span>\r\n                <span style=\"color:blue\">Next</span>\r\n                zip.SaveSelfExtractor(<span style=\"color:#a31515\">&quot;archive.exe&quot;</span>, SelfExtractorFlavor.ConsoleApplication)\r\n            <span style=\"color:blue\">End</span> <span style=\"color:blue\">Using</span>\r\n\r\n\r\n            <span style=\"color:blue\">If</span> emptyCheckboxList = <span style=\"color:blue\">False</span> <span style=\"color:blue\">Then</span>\r\n                ErrorLbl.Text = <span style=\"color:#a31515\">&quot;No File was chosen for download, please select files &quot;</span>\r\n            <span style=\"color:blue\">Else</span>\r\n                ErrorLbl.Text = <span style=\"color:#a31515\">&quot;&quot;</span>\r\n            <span style=\"color:blue\">End</span> <span style=\"color:blue\">If</span>\r\n\r\n        <span style=\"color:blue\">Catch</span> ex <span style=\"color:blue\">As</span> Exception\r\n            ErrorLbl.Text = <span style=\"color:#a31515\">&quot;Download_Click: &quot;</span> &amp; ex.Message\r\n            <span style=\"color:blue\">Return</span>\r\n        <span style=\"color:blue\">End</span> <span style=\"color:blue\">Try</span>\r\n\r\n    <span style=\"color:blue\">End</span> <span style=\"color:blue\">Sub</span>\r\n</pre>\r\n</div>\r\n<p></p>\r\n",
    "PostedDate": "2010-11-11T09:51:35.67-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "520709",
    "ThreadId": "234342",
    "Html": "\r\n<p>I suspect the reason you get the instruction error is that the EXE image on the web browser machine is either empty or else contains only junk.</p>\r\n<p>What you have looks pretty good, except...</p>\r\n<ol>\r\n<li>You're saving the self-extractor to a filename called &quot;archive.exe&quot;.&nbsp; This is going to be a file that is&nbsp;local to the web server.&nbsp; You will want to explicitly specify a temporary directory path here, eg c:\\temp\\iisdirectory or something.&nbsp;\r\n I'm surprised that the code, as written, is working.&nbsp; Typically ASPNET does not have write permissions in the &quot;current working directory&quot; where it runs, which is often c:\\windows\\system32.&nbsp; &nbsp;So you will want to explicitly specify the&nbsp;directory\r\n to hold the temporary zip file on the server.&nbsp; You want this in an explicit,&nbsp;well-known location, to ease the job of removal of any stray temporary files, should that be necessary.&nbsp; You could also use&nbsp;System.IO.Path.GetTempPath&nbsp; or\r\n Environment.GetEnvironmentVariable(&quot;temp&quot;) for this location.&nbsp; I won't advise you on the pros and cons of each of those options.\r\n</li><li>Grant WRITE permissions to the ASPNET user to that temporary directory.&nbsp; You could also just use the IIS_USRS group.&nbsp; (I think that is the correct spelling). Grant write permissions on your desired temp staging directory on the server to that\r\n user or group. </li><li>In the current code, you don't actually write the content of archive.exe to the Response.OutputStream.&nbsp; The way you have it written, you prepare the Response.OutputStream to get content, then you save a zipfile to the filesystem on the server, and\r\n nothing gets written to the web browser.&nbsp; To write the content to the web browser,&nbsp; AFTER calling&nbsp;zip.Save(&quot;archive.exe&quot;...), &nbsp;and outside the scope of the containing Using clause, you will need to open a filestream on &quot;archive.exe&quot; or\r\n whatever you named your temp file, then read the bytes from that temp file, and write them to Response.OutputStream.\r\n</li><li>Finally, call Response.Close(). </li><li>After all the bytes are streamed to the browser, and you've called Response.Close(), delete the temporary file with System.IO.File.Delete(&quot;whatever&quot;).\r\n</li></ol>\r\n<p>&nbsp;</p>\r\n<p>Good luck.</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n",
    "PostedDate": "2010-11-11T10:55:32.59-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "521140",
    "ThreadId": "234342",
    "Html": "\r\n<p>hi Cheeso, youre &nbsp;a life saver ! thanks</p>\r\n<p>if anyone might find this useful , here is the code, it might be a bit messy but it works for me:</p>\r\n<p>&nbsp;</p>\r\n<p></p>\r\n<div style=\"color:black; background-color:white\">\r\n<pre style=\"color:black\">   <span style=\"color:blue\">Protected</span> <span style=\"color:blue\">Sub</span> Download1_Click(<span style=\"color:blue\">ByVal</span> sender <span style=\"color:blue\">As</span> <span style=\"color:blue\">Object</span>, <span style=\"color:blue\">ByVal</span> e <span style=\"color:blue\">As</span> EventArgs) <span style=\"color:blue\">Handles</span> Download1.Click\r\n        <span style=\"color:blue\">Try</span>\r\n\r\n            <span style=\"color:blue\">Dim</span> emptyCheckboxList <span style=\"color:blue\">As</span> <span style=\"color:blue\">Boolean</span> = <span style=\"color:blue\">False</span>\r\n            <span style=\"color:blue\">Dim</span> ItemsNum <span style=\"color:blue\">As</span> Int32 = chklst.Items.<span style=\"color:blue\">Count</span>()\r\n            <span style=\"color:blue\">Dim</span> MyFileStream <span style=\"color:blue\">As</span> FileStream\r\n            <span style=\"color:blue\">Dim</span> FileSize <span style=\"color:blue\">As</span> <span style=\"color:blue\">Long</span>\r\n            <span style=\"color:blue\">Dim</span> fp <span style=\"color:blue\">As</span> StreamWriter\r\n\r\n            Response.Clear()\r\n\r\n            <span style=\"color:blue\">Using</span> zip <span style=\"color:blue\">As</span> <span style=\"color:blue\">New</span> ZipFile()\r\n\r\n                <span style=\"color:blue\">For</span> <span style=\"color:blue\">Each</span> lstItem <span style=\"color:blue\">In</span> chklst.Items\r\n\r\n                    <span style=\"color:blue\">If</span> lstItem.Selected = <span style=\"color:blue\">True</span> <span style=\"color:blue\">Then</span>\r\n                        emptyCheckboxList = <span style=\"color:blue\">True</span>\r\n                        zip.AddFile(Server.MapPath(<span style=\"color:#a31515\">&quot;.\\files\\&quot;</span>) &amp; lstItem.ToString, <span style=\"color:#a31515\">&quot;&quot;</span>)\r\n                    <span style=\"color:blue\">End</span> <span style=\"color:blue\">If</span>\r\n                <span style=\"color:blue\">Next</span></pre>\r\n<pre><span style=\"color:blue\">&nbsp;</span><span style=\"white-space:pre\">\t\t</span>' save self extracting file to server\r\n                zip.SaveSelfExtractor(Server.MapPath(<span style=\"color:#a31515\">&quot;.\\files\\temp\\&quot;</span>) &amp; <span style=\"color:#a31515\">&quot;archive.exe&quot;</span>, SelfExtractorFlavor.ConsoleApplication)\r\n            <span style=\"color:blue\">End</span> <span style=\"color:blue\">Using</span>\r\n\r\n          \r\n            MyFileStream = <span style=\"color:blue\">New</span> FileStream(Server.MapPath(<span style=\"color:#a31515\">&quot;.\\files\\temp\\&quot;</span>) &amp; <span style=\"color:#a31515\">&quot;archive.exe&quot;</span>, FileMode.Open)\r\n            FileSize = MyFileStream.Length\r\n\r\n            <span style=\"color:blue\">Dim</span> Buffer(<span style=\"color:blue\">CInt</span>(FileSize)) <span style=\"color:blue\">As</span> <span style=\"color:blue\">Byte</span>\r\n            MyFileStream.Read(Buffer, 0, <span style=\"color:blue\">CInt</span>(FileSize))\r\n            MyFileStream.Close()\r\n\r\n            Response.ContentType = <span style=\"color:#a31515\">&quot;application/exe&quot;</span>\r\n             Response.AddHeader(<span style=\"color:#a31515\">&quot;Content-Disposition&quot;</span>, <span style=\"color:#a31515\">&quot;attachment; filename=archive.exe&quot;</span>)\r\n            Response.OutputStream.Write(Buffer, 0, FileSize)\r\n            Response.Flush()\r\n            Response.Close()\r\n\r\n            <span style=\"color:blue\">If</span> emptyCheckboxList = <span style=\"color:blue\">False</span> <span style=\"color:blue\">Then</span>\r\n                ErrorLbl.Text = <span style=\"color:#a31515\">&quot;No File was chosen for download, please select files &quot;</span>\r\n            <span style=\"color:blue\">Else</span>\r\n                ErrorLbl.Text = <span style=\"color:#a31515\">&quot;&quot;</span>\r\n            <span style=\"color:blue\">End</span> <span style=\"color:blue\">If</span>\r\n\r\n        <span style=\"color:blue\">Catch</span> ex <span style=\"color:blue\">As</span> Exception\r\n            ErrorLbl.Text = <span style=\"color:#a31515\">&quot;Download_Click: &quot;</span> &amp; ex.Message\r\n           \r\n            <span style=\"color:blue\">Return</span>\r\n        <span style=\"color:blue\">End</span> <span style=\"color:blue\">Try</span>\r\n         \r\n    <span style=\"color:blue\">End</span> <span style=\"color:blue\">Sub</span>\r\n</pre>\r\n</div>\r\n<p></p>\r\n",
    "PostedDate": "2010-11-12T08:01:47.14-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "521174",
    "ThreadId": "234342",
    "Html": "\r\n<p>Looks really good.</p>\r\n<p>Couple more things.</p>\r\n<ol>\r\n<li><a href=\"http://msdn.microsoft.com/en-us/library/system.io.filestream.aspx\">FileStream is Disposable</a>.&nbsp; You should wrap it in a using clause, just as you do with ZipFile. If you don't, then you run the risk of keeping files open longer than necessary\r\n on your server, and also not being able to delete the file when your code is finished reading it.\r\n</li><li>When you read the exe file, you should do so in chunks that are a well-known and reasonable size. Currently you check the size of the file, then allocate an array that is equal to the size of the file, in size, then read in the entire file, then write out\r\n that entire array to Response.OutputStream.&nbsp; This works, but it allocates an array that is of unknown size and potentially very large.&nbsp; Imagine an exe that is 1gb in size.&nbsp; You would have to allocate an array of that size.&nbsp; This will likely\r\n fail.&nbsp;&nbsp; Instead, read the file and write the output in chunks, like this:\r\n</li></ol>\r\n<div style=\"color:black; background-color:white\">\r\n<pre><span style=\"color:blue\">Response.ContentType = <span style=\"color:#a31515\">&quot;application/exe&quot;</span><br>Response.AddHeader(<span style=\"color:#a31515\">&quot;Content-Disposition&quot;</span>, <span style=\"color:#a31515\">&quot;attachment; filename=archive.exe&quot;</span>)<br></span></pre>\r\n<pre><span style=\"color:blue\">Using</span> fs <span style=\"color:blue\">as</span> <span style=\"color:blue\">New</span> Filestream(<span style=\"color:#a31515\">&quot;mytempfile.exe&quot;</span>)\r\n    <span style=\"color:blue\">Dim</span> Buffer(2048) <span style=\"color:blue\">as</span> <span style=\"color:blue\">Byte</span>\r\n    <span style=\"color:blue\">Dim</span> n <span style=\"color:blue\">as</span> Int32\r\n    <span style=\"color:blue\">Do</span>\r\n        n = fs.Read(Buffer, 0, 2048)\r\n        Response.OutputStream.Write(Buffer, 0, n)\r\n    <span style=\"color:blue\">Loop</span> <span style=\"color:blue\">While</span> n &gt; 0\r\n<span style=\"color:blue\">End</span> <span style=\"color:blue\">Using</span>\r\nResponse.Flush()<br>Response.Close()<br><br></pre>\r\n</div>\r\n<p>Good luck!</p>\r\n<p>&nbsp;</p>\r\n",
    "PostedDate": "2010-11-12T09:24:53.437-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "522602",
    "ThreadId": "234342",
    "Html": "\r\n<p>Hi Cheeso, thank you for that tip.</p>\r\n<p>i was trying to implement your suggestion and ran into an error &quot;Overload resolution failed because no accessible 'New' accepts this number of arguments Error&quot; coming from this command</p>\r\n<div style=\"color:black; background-color:white\">\r\n<pre><div style=\"color:black; background-color:white\"><pre><span style=\"color:blue\">Using</span> fs <span style=\"color:blue\">as</span> <span style=\"color:blue\">New</span> Filestream(<span style=\"color:#a31515\">&quot;mytempfile.exe&quot;</span>)\r\n</pre>\r\n</div>\r\n</pre>\r\n</div>\r\n<p>so i looked it up and saw you need 3 parameters for Filestream.</p>\r\n<p>i tried using the following:</p>\r\n<p></p>\r\n<div style=\"color:black; background-color:white\">\r\n<pre><span style=\"color:blue\">Using</span> fs <span style=\"color:blue\">as</span> <span style=\"color:blue\">New</span> Filestream(Server.MapPath(<span style=\"color:#a31515\">&quot;.\\files\\temp\\&quot;</span>) &amp; exeFileName, FileMode.OpenOrCreate, FileAccess.Read)\r\n</pre>\r\n</div>\r\n<p></p>\r\n<p>&nbsp;</p>\r\n<p>and it looks like its working now.</p>\r\n<p>Thanks again.</p>\r\n<p>Buzi</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n<div style=\"color:black; background-color:white\">\r\n<pre><br></pre>\r\n</div>\r\n",
    "PostedDate": "2010-11-16T03:21:00.45-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "522667",
    "ThreadId": "234342",
    "Html": "\r\n<p>Ah, yes, you're correct. Thanks for catching that. I was thinking of File.OpenRead().</p>\r\n<p>If you want to clean&nbsp;up that code a little, you can get a FileStream also from calling the static&nbsp;<a href=\"http://msdn.microsoft.com/en-us/library/system.io.file.openread.aspx\">File.OpenRead() method with a single argument</a>, the filename. Some\r\n people prefer the more general approach using New FileStream.</p>\r\n<p>&nbsp;</p>\r\n",
    "PostedDate": "2010-11-16T06:06:47.14-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "522749",
    "ThreadId": "234342",
    "Html": "\r\n<p>By the way. im not sure if i should open a new thread on this. but im facing an issue with the self extracting file:</p>\r\n<p>on some pc's when trying to open this file i get this error message box:</p>\r\n<p>&nbsp;</p>\r\n<p><strong>&quot;.NET Framework Initialization Error</strong></p>\r\n<p><strong>to run this application you first must install one of the following versions of the .NET Framework v4.0...&quot;</strong></p>\r\n<p>my application is targeting the <strong>.NET 4.0 framework</strong>.</p>\r\n<p>is there some workaround or a way to bundle the&nbsp;.Net framework with the installed if its not installed on the computer ?</p>\r\n<p>have you seen this issue before ?</p>\r\n<p>Thanks</p>\r\n<p>Buzi</p>\r\n<p>&nbsp;</p>\r\n",
    "PostedDate": "2010-11-16T08:28:41.493-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "522861",
    "ThreadId": "234342",
    "Html": "\r\n<p>yes, please open a new thread.</p>\r\n",
    "PostedDate": "2010-11-16T11:22:59.817-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]