PDA

View Full Version : پشتیبان گیری در vb



mohamad6
یک شنبه 25 خرداد 1382, 09:39 صبح
سلام
چطوری می‌شه از فایلهای اکسس در vb پشتیبان تهیه کرد؟

Vahid_Nasiri
چهارشنبه 28 خرداد 1382, 00:55 صبح
فایل دی بی اکسس مانند دیتابیس SQL server نیست که حتما نیاز به تولید Backup داشته باشد...... اینجا یک کپی و پیست معمولی حلال مشکلات است! اگر دوست داشتید می توانید یکی از کامپوننت های Zip کن را هم به برنامه برای خوشگلی بیشتر اضافه کنید. در کل موضوع زیاد مهمی نیست و زیاد آنرا جدی نگیرید! :lol:

سعید قدیری مقدم
چهارشنبه 28 خرداد 1382, 08:41 صبح
سلام آقای نصیری میشه نام یک کامپونیت zip کننده رو نام ببری؟ :) ممنون

Vahid_Nasiri
چهارشنبه 28 خرداد 1382, 12:30 عصر
آقای دلفی اسیستنت در سایت قبلی چندتا کامپوننت در این باره آپلود کرده بودند. از ایشان بخواهید تا لطفا دوباره اینکار را انجام دهند.... یا به فوروم قدیمی سایت یک سری بزنید :wink:

mohamad6
پنج شنبه 29 خرداد 1382, 09:26 صبح
آقای نصیری من می‌خواهم در داخل برنامه vb از فایل access پشتیبان تهیه کنم خواهشاً نام توابع کپی و پیست کردن را بگویید.

saman_itc
یک شنبه 11 آذر 1386, 20:35 عصر
آقای نصیری ما همون کدی که میشه از طریق OpenFileDialogو seveFileDialog بشه اونو جایی کپی و بازیابی کذد میخواهیم .که شما خیلی کلی فرمودین.درصورت امکان بیشتر توضیح بدین تو vb.2005

JaVaD_1900
چهارشنبه 28 آذر 1386, 11:08 صبح
چطور در خود access فایل پشتیبان تهیه کنیم ؟
اصلا این امکان در access وجود دارد ؟

ir_programmer
چهارشنبه 28 آذر 1386, 12:07 عصر
ابتدا کلاس زیر رو به پروژتون اضافه کنید.

Imports System.IO
Imports System.IO.Compression

Public Class ZipUtility

Public Sub CompressFile(ByVal sourceFile As String, ByVal destinationFile As String)

' make sure the source file is there
If Not File.Exists(sourceFile) Then
Throw New FileNotFoundException
End If

' Create the streams and byte arrays needed
Dim buffer As Byte() = Nothing
Dim sourceStream As FileStream = Nothing
Dim destinationStream As FileStream = Nothing
Dim compressedStream As GZipStream = Nothing

Try
' Read the bytes from the source file into a byte array
sourceStream = New FileStream(sourceFile, FileMode.Open, FileAccess.Read, FileShare.Read)

' Read the source stream values into the buffer
buffer = New Byte(sourceStream.Length) {}
Dim checkCounter As Integer = sourceStream.Read(buffer, 0, buffer.Length)

' Open the FileStream to write to
destinationStream = New FileStream(destinationFile, FileMode.OpenOrCreate, FileAccess.Write)

' Create a compression stream pointing to the destiantion stream
compressedStream = New GZipStream(destinationStream, CompressionMode.Compress, True)

'Now write the compressed data to the destination file
compressedStream.Write(buffer, 0, buffer.Length)

Catch ex As ApplicationException
MessageBox.Show(ex.Message, "An Error occured during compression", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
' Make sure we allways close all streams
If sourceStream IsNot Nothing Then
sourceStream.Close()
End If
If compressedStream IsNot Nothing Then
compressedStream.Close()
End If
If destinationStream IsNot Nothing Then
destinationStream.Close()
End If
End Try

End Sub

Public Sub DecompressFile(ByVal sourceFile As String, ByVal destinationFile As String)

' make sure the source file is there
If Not File.Exists(sourceFile) Then
Throw New FileNotFoundException
End If

' Create the streams and byte arrays needed
Dim sourceStream As FileStream = Nothing
Dim destinationStream As FileStream = Nothing
Dim decompressedStream As GZipStream = Nothing
Dim quartetBuffer As Byte() = Nothing

Try
' Read in the compressed source stream
sourceStream = New FileStream(sourceFile, FileMode.Open)

' Create a compression stream pointing to the destiantion stream
decompressedStream = New GZipStream(sourceStream, CompressionMode.Decompress, True)

' Read the footer to determine the length of the destiantion file
quartetBuffer = New Byte(4) {}
Dim position As Integer = CType(sourceStream.Length, Integer) - 4
sourceStream.Position = position
sourceStream.Read(quartetBuffer, 0, 4)
sourceStream.Position = 0
Dim checkLength As Integer = BitConverter.ToInt32(quartetBuffer, 0)

Dim buffer(checkLength + 100) As Byte
Dim offset As Integer = 0
Dim total As Integer = 0

' Read the compressed data into the buffer
While True
Dim bytesRead As Integer = decompressedStream.Read(buffer, offset, 100)
If bytesRead = 0 Then
Exit While
End If
offset += bytesRead
total += bytesRead
End While

' Now write everything to the destination file
destinationStream = New FileStream(destinationFile, FileMode.Create)
destinationStream.Write(buffer, 0, total)

' and flush everyhting to clean out the buffer
destinationStream.Flush()

Catch ex As ApplicationException
MessageBox.Show(ex.Message, "An Error occured during compression", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
' Make sure we allways close all streams
If sourceStream IsNot Nothing Then
sourceStream.Close()
End If
If decompressedStream IsNot Nothing Then
decompressedStream.Close()
End If
If destinationStream IsNot Nothing Then
destinationStream.Close()
End If
End Try

End Sub
End Class


بعد تو برنامه اینجوری استفاده کنید:

Dim Comp As New ZipUtility

Comp.CompressFile("c:\source.mdb", "c:\dest.zip")

ir_programmer
چهارشنبه 28 آذر 1386, 12:08 عصر
این کلاس open source هست و میتونید تو همه پروژهاتون استفاده کنید.