issue using SelfExtractorSaveOptions

Nov 25, 2010 at 4:18 PM



The 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.("c:\extract_temp") right now its extracting it into the same folder it was downloaded to.

on another note. is it possible to tell the OutputStream to give the browser a default location of where to save the file ?

for example. i would like that when the button is clicked, it will open the "save to" dialog with the preferred folder already appearing as the default location.



   Protected Sub Download1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Download1.Click
            System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("he-IL")
            Dim emptyCheckboxList As Boolean = False
            Dim ItemsNum As Int32 = chklst.Items.Count()
            Dim MyFileStream As FileStream
            Dim FileSize As Long
            Dim fp As StreamWriter
            Dim log As log4net.ILog

            Dim exeFileName As String = & "_" & DateTime.Now.ToString("ddMMyyyy") & "_" & DateTime.Now.ToString("HHmmss") & ".exe"


            Using zip As New ZipFile()

                For Each lstItem In chklst.Items
                 debug1.Text = debug1.Text & "item"
                    If lstItem.Selected = True Then
                        emptyCheckboxList = True
                         zip.AddFile(Server.MapPath(".\files\" & & "\") & lstItem.ToString, DateTime.Now.ToString("ddMMyyyy") & "_" & DateTime.Now.ToString("HHmmss"))

                    End If

                Dim options As New Ionic.Zip.SelfExtractorSaveOptions()
                options.DefaultExtractDirectory = "c:\extract_temp"
                options.ExtractExistingFile = Ionic.Zip.ExtractExistingFileAction.OverwriteSilently
                options.Flavor = Ionic.Zip.SelfExtractorFlavor.ConsoleApplication
                options.Quiet = True
                options.RemoveUnpackedFilesAfterExecute = True

                zip.SaveSelfExtractor(Server.MapPath(".\files\temp\") & exeFileName, SelfExtractorFlavor.ConsoleApplication)
            End Using
            MyFileStream = New FileStream(Server.MapPath(".\files\temp\") & exeFileName, FileMode.Open)
            FileSize = MyFileStream.Length

            Dim Buffer(CInt(FileSize)) As Byte
            MyFileStream.Read(Buffer, 0, CInt(FileSize))

           Response.ContentType = "application/exe"
             Response.AddHeader("Content-Disposition", "attachment; filename=" & exeFileName)

            Using fs as New Filestream(Server.MapPath(".\files\temp\") & exeFileName, FileMode.OpenOrCreate, FileAccess.Read)
                Dim Buffer2(2048) as Byte
                Dim n as Int32
                    n = fs.Read(Buffer2, 0, 2048)
                    Response.OutputStream.Write(Buffer2, 0, n)
                Loop While n > 0
           End Using

            If emptyCheckboxList = False Then
                ErrorLbl.Text = "No File was chosen for download, please select files "
                ErrorLbl.Text = ""
            End If

        Catch ex As Exception
            ErrorLbl.Text = "Download_Click: " & ex.Message
        End Try
         System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-US")  
    End Sub