20-02-23, 08:35 AM
(آخر تعديل لهذه المشاركة : 20-02-23, 08:36 AM {2} بواسطة محمد فوزى محمد.)
تاكد ان Windows.base موجودة فى Referance
Imports System.IO
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim SFD As New SaveFileDialog
Try
With SFD
.Filter = "Bacup file |*.bak*"
.FileName = "d:\data_back_up\" & Format(Now, "yyyy_MM_dd_hh_mm_ss")
End With
If SFD.ShowDialog = System.Windows.Forms.DialogResult.OK Then
SS = SFD.FileName & ".bak"
Dim sql As String = "backup database my_store to disk = '" & (SS) & " '"
Dim cmd As New SqlCommand(sql, DB)
cmd.ExecuteNonQuery()
End If
'-------------------الضغط-------------------------------
Dim Z As System.IO.Packaging.ZipPackage
Z = System.IO.Packaging.Package.Open(SS & ".zip", IO.FileMode.Create)
Dim B = System.IO.File.ReadAllBytes(SS)
Dim Partx As Uri = System.IO.Packaging.PackUriHelper.CreatePartUri(New Uri(System.IO.Path.GetFileName(SS), UriKind.Relative))
Dim P = Z.CreatePart(Partx, System.Net.Mime.MediaTypeNames.Application.Zip, IO.Packaging.CompressionOption.Maximum)
P.GetStream.Write(B, 0, B.Length)
Z.Close()
Dim fileToDelete As String = SS
If File.Exists(fileToDelete) = True Then
File.Delete(fileToDelete)
End If
Alert("تمت عملية النسخ الاحتياطى بنجاح", Form_Alert.enmType.Success)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Imports System.IO
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim SFD As New SaveFileDialog
Try
With SFD
.Filter = "Bacup file |*.bak*"
.FileName = "d:\data_back_up\" & Format(Now, "yyyy_MM_dd_hh_mm_ss")
End With
If SFD.ShowDialog = System.Windows.Forms.DialogResult.OK Then
SS = SFD.FileName & ".bak"
Dim sql As String = "backup database my_store to disk = '" & (SS) & " '"
Dim cmd As New SqlCommand(sql, DB)
cmd.ExecuteNonQuery()
End If
'-------------------الضغط-------------------------------
Dim Z As System.IO.Packaging.ZipPackage
Z = System.IO.Packaging.Package.Open(SS & ".zip", IO.FileMode.Create)
Dim B = System.IO.File.ReadAllBytes(SS)
Dim Partx As Uri = System.IO.Packaging.PackUriHelper.CreatePartUri(New Uri(System.IO.Path.GetFileName(SS), UriKind.Relative))
Dim P = Z.CreatePart(Partx, System.Net.Mime.MediaTypeNames.Application.Zip, IO.Packaging.CompressionOption.Maximum)
P.GetStream.Write(B, 0, B.Length)
Z.Close()
Dim fileToDelete As String = SS
If File.Exists(fileToDelete) = True Then
File.Delete(fileToDelete)
End If
Alert("تمت عملية النسخ الاحتياطى بنجاح", Form_Alert.enmType.Success)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
