app sluiten na zip file creeren

Status
Niet open voor verdere reacties.

mustangBE

Gebruiker
Lid geworden
2 jun 2007
Berichten
349
ik heb volgende code om een zip file te maken van mijn bestanden (backup).
hoe kan ik mijn app sluiten als het zippen voltooid is ?
als ik me.close na Zip() zet sluit hij al voor het zippen klaar is .

Code:
Private Sub Home_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
       Try

            Dim response_close As MsgBoxResult
            response_close = MsgBox("Beheer afsluiten", CType(MsgBoxStyle.Question + MsgBoxStyle.YesNo, MsgBoxStyle), "")

            If response_close = MsgBoxResult.Yes Then


                If instellingen.sw_backup.Value = True Then
                    zip()
                ElseIf instellingen.sw_backup.Value = False Then
                    e.Cancel = False
                End If

            ElseIf response_close = MsgBoxResult.No Then
                e.Cancel = True
            End If


        Catch ex As Exception
            MsgBox(ex.Message)
        End Try


    End Sub

   
   
    Sub zip()

        Dim startBuffer() As Byte = {80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

        FileIO.FileSystem.WriteAllBytes(instellingen.txt_BackupDestination.Text & "\" & instellingen.txt_backup_name.Text & ".zip", startBuffer, False)

        Dim sc As New Shell32.Shell()
        Dim input As Shell32.Folder = sc.NameSpace(instellingen.txt_BackupSource.Text)
        Dim output As Shell32.Folder = sc.NameSpace(instellingen.txt_BackupDestination.Text & "\" & instellingen.txt_backup_name.Text & ".zip")
        output.CopyHere(input.Items, 4)


    End Sub
 
als ik
Code:
application.close
toevoeg blijft mijn msgbox open staan en wordt de app niet gesloten.
kan het iets te maken hebben met het feit dat de code in Mybase.formclosing staat ?

Code:
Private Sub Home_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        Try
            Dim response_close As MsgBoxResult
            response_close = MsgBox("Beheer afsluiten", CType(MsgBoxStyle.Question + MsgBoxStyle.YesNo, MsgBoxStyle), "")

            If response_close = MsgBoxResult.Yes Then

                If instellingen.sw_backup.Value = True Then
                    zip()
                    Application.Exit()

                ElseIf instellingen.sw_backup.Value = False Then
                    e.Cancel = False
                End If

            ElseIf response_close = MsgBoxResult.No Then

                e.Cancel = True
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub
 
Dat is ook waar ik aan zat te denken. Je kan proberen om voor het aanroepen van "zip" ook nog "e.cancel" te doen en dan aan het eind van de sub "zip" nog "application.exit".

Dus zoiets (alleen dan iets aangepast):
[CPP]
Private Sub Home_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
e.Cancel = True
zip()
End Sub

Private Sub zip()
''\\ Bestand zippen
Application.Exit()
End Sub
[/CPP]

Het is even snel uit de losse hand geschreven, dus het zal niet in een keer werken voor jou, het is alleen om even te verduidelijken wat ik bedoel.

Ik weet ook niet zeker of dit het probleem zal oplossen, maar je kan het proberen...

MartinJM
 
met deze code gaat het wel, als het zippen gedaan is sluit de app.
Code:
 Sub zip() 

 Dim fileDateTime As String = DateTime.Now.ToString("ddMMyyyy") & "_" & DateTime.Now.ToString("HHmmss") 
 Dim startPath As String = (instellingen.txt_BackupSource.Text) 
 Dim zipPath As String = (instellingen.txt_BackupDestination.Text & "beheer" & fileDateTime & ".zip") 

 ZipFile.CreateFromDirectory(startPath, zipPath) 

 End Sub

met de shel32 code kreeg ik automatisch een msgbox van het lopende proces en de files die werden gezipt.
Code:
Sub Zip() 
 Dim startBuffer() As Byte = {80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, _ 
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} 
 FileIO.FileSystem.WriteAllBytes("d:\empty.zip", startBuffer, False) 
 Dim sc As New Shell32.Shell() 
 Dim input As Shell32.Folder = sc.NameSpace("D:\neededFiles") 
 Dim output As Shell32.Folder = sc.NameSpace("D:\empty.zip") 
 output.CopyHere(input.Items, 4) 

 End Sub

kan ik dit op een makkelijke manier ook met de nieuwe code ?
als ik een extra form aanmaak voor een progress bar enz. in te zetten zit ik terug met het afsluit probleem.
 
Hoi,

In principe kan je gewoon nog een form openen, zolang je het maar afsluit bij het 'echte' afsluiten.

Ik ga even kijken of ik iets voor je kan vinden waar je iets aan hebt :)

MartinJM
 
een voorbeeldje zou prachtig zijn , ik wil er een progress bar in zetten en dergelijke
 
Hoi,

Ik heb een klein voorbeeldje gemaakt op basis van de code in deze link: http://www.codeproject.com/Articles/28107/Zip-Files-Easy

Ik had zelf namelijk een beetje problemen met het vinden van de IO.Compression.FileSystem Dll. Dus heb ik een andere manier gezocht :)

Het zit daardoor misschien wel iets ingewikkelder, maar juist daardoor heb je ook meer controle. Ik heb de code gemaakt in een simpel form met daarop alleen een button en een progressbar, dus je zal het nog enigszins moeten aanpassen zodat het helemaal voor jou werkt.

[CPP]Imports System.IO.Packaging

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Zip("ZipFile", "FileToZip")
End Sub

Private Sub Zip(ByVal ZipPath As String, ByVal FilePath As String)
Dim Z As Package = ZipPackage.Open(ZipPath, IO.FileMode.OpenOrCreate, IO.FileAccess.ReadWrite)
Dim PartUri As Uri = New Uri(String.Concat("/", IO.Path.GetFileName(FilePath.Replace(" ", "_"))), UriKind.Relative)
Dim ContentType As String = Net.Mime.MediaTypeNames.Application.Zip
Dim PP As PackagePart = Z.CreatePart(PartUri, ContentType, CompressionOption.Normal)
Dim Bytes As Byte() = IO.File.ReadAllBytes(FilePath)

ProgressBar1.Minimum = 0
ProgressBar1.Maximum = Bytes.Length - 1
Dim Str As IO.Stream = PP.GetStream()
For i As Integer = 0 To Bytes.Length - 1 Step 1
Str.WriteByte(Bytes(i))
ProgressBar1.Value = i
Next

ProgressBar1.Value = 0

Z.Close()
End Sub
End Class
[/CPP]

Ik hoop dat hiermee je vraag is opgelost!

Succes! :thumb:
MartinJM
 
Laatst bewerkt:
Status
Niet open voor verdere reacties.

Nieuwste berichten

Terug
Bovenaan Onderaan