[
  {
    "Id": "527024",
    "ThreadId": "236055",
    "Html": "\r\n<p>&nbsp;</p>\r\n<p>Hi,</p>\r\n<p>The&nbsp;<span style=\"font-family:Consolas,'Courier New',Courier,monospace; white-space:pre\">SelfExtractorSaveOptions are not working for me for some reason in this code, i want the .exe file to extract the folder with the files into a specific folder.(</span><span style=\"font-family:Consolas,'Courier New',Courier,monospace; white-space:pre\"><span>&quot;c:\\extract_temp&quot;</span>)\r\n right now its extracting it into the same folder it was downloaded to.</span></p>\r\n<p><span style=\"font-family:Consolas,'Courier New',Courier,monospace; white-space:pre\">on another note. is it possible to tell the OutputStream to give the browser a default location of where to save the file ?\r\n</span></p>\r\n<p><span style=\"font-family:Consolas,'Courier New',Courier,monospace; white-space:pre\">for example. i would like that when the button is clicked, it will open the &quot;save to&quot; dialog with the preferred folder already appearing as the default location.</span></p>\r\n<p><span style=\"font-family:Consolas,'Courier New',Courier,monospace; white-space:pre\">Thanks.</span></p>\r\n<p>&nbsp;</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            System.Threading.Thread.CurrentThread.CurrentCulture = <span style=\"color:blue\">New</span> System.Globalization.CultureInfo(<span style=\"color:#a31515\">&quot;he-IL&quot;</span>)\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            <span style=\"color:blue\">Dim</span> log <span style=\"color:blue\">As</span> log4net.ILog\r\n\r\n            <span style=\"color:blue\">Dim</span> exeFileName <span style=\"color:blue\">As</span> <span style=\"color:blue\">String</span> = context.user.identity.name &amp; <span style=\"color:#a31515\">&quot;_&quot;</span> &amp; DateTime.Now.ToString(<span style=\"color:#a31515\">&quot;ddMMyyyy&quot;</span>) &amp; <span style=\"color:#a31515\">&quot;_&quot;</span> &amp; DateTime.Now.ToString(<span style=\"color:#a31515\">&quot;HHmmss&quot;</span>) &amp; <span style=\"color:#a31515\">&quot;.exe&quot;</span>\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                 debug1.Text = debug1.Text &amp; <span style=\"color:#a31515\">&quot;item&quot;</span>\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; context.user.identity.name &amp; <span style=\"color:#a31515\">&quot;\\&quot;</span>) &amp; lstItem.ToString, DateTime.Now.ToString(<span style=\"color:#a31515\">&quot;ddMMyyyy&quot;</span>) &amp; <span style=\"color:#a31515\">&quot;_&quot;</span> &amp; DateTime.Now.ToString(<span style=\"color:#a31515\">&quot;HHmmss&quot;</span>))\r\n\r\n                    <span style=\"color:blue\">End</span> <span style=\"color:blue\">If</span>\r\n                <span style=\"color:blue\">Next</span>\r\n\r\n                <span style=\"color:blue\">Dim</span> options <span style=\"color:blue\">As</span> <span style=\"color:blue\">New</span> Ionic.Zip.SelfExtractorSaveOptions()\r\n                options.DefaultExtractDirectory = <span style=\"color:#a31515\">&quot;c:\\extract_temp&quot;</span>\r\n                options.ExtractExistingFile = Ionic.Zip.ExtractExistingFileAction.OverwriteSilently\r\n                options.Flavor = Ionic.Zip.SelfExtractorFlavor.ConsoleApplication\r\n                options.Quiet = <span style=\"color:blue\">True</span>\r\n                options.RemoveUnpackedFilesAfterExecute = <span style=\"color:blue\">True</span>\r\n\r\n                zip.SaveSelfExtractor(Server.MapPath(<span style=\"color:#a31515\">&quot;.\\files\\temp\\&quot;</span>) &amp; exeFileName, 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; exeFileName, 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=&quot;</span> &amp; exeFileName)\r\n\r\n            <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                <span style=\"color:blue\">Dim</span> Buffer2(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(Buffer2, 0, 2048)\r\n                    Response.OutputStream.Write(Buffer2, 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\n            Response.Flush()\r\n            Response.Close()\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           \r\n            <span style=\"color:blue\">Return</span>\r\n        <span style=\"color:blue\">End</span> <span style=\"color:blue\">Try</span>\r\n         System.Threading.Thread.CurrentThread.CurrentCulture = <span style=\"color:blue\">New</span> System.Globalization.CultureInfo(<span style=\"color:#a31515\">&quot;en-US&quot;</span>)  \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-25T09:18:49.15-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]