Public Sub SaveBinaryFile(strFilename As String, bytesToWrite() As Byte)
Dim position As Integer = 0
Using fsNew As FileStream = New FileStream(strFilename, FileMode.Create, FileAccess.Write)
Do
Dim intToCopy As Integer = Math.Min(4096, bytesToWrite.Length - position)
Dim buffer(intToCopy - 1) As Byte
Array.Copy(bytesToWrite, position, buffer, 0, intToCopy)
fsNew.Write(buffer, 0, buffer.Length)
ProgressBar1.Value = ((position / bytesToWrite.Length) * 100)
Application.DoEvents()
position += intToCopy
Loop While position < bytesToWrite.Length
End Using
End Sub
Code (C#)
public void SaveBinaryFile(string strFilename, byte[] bytesToWrite)
{
int position = 0;
using (FileStream fsNew = new FileStream(strFilename, FileMode.Create, FileAccess.Write)) {
do {
int intToCopy = Math.Min(4096, bytesToWrite.Length - position);
byte[] buffer = new byte[intToCopy];
Array.Copy(bytesToWrite, position, buffer, 0, intToCopy);
fsNew.Write(buffer, 0, buffer.Length);
ProgressBar1.Value = ((position / bytesToWrite.Length) * 100);
Application.DoEvents();
position += intToCopy;
} while (position < bytesToWrite.Length);
}
}