In this article I will explain with an example, how to save BYTE Array to audio file (MP3) in
Windows Forms (WinForms) Application using C# and VB.Net.
Form Design
The Form consists of following control:
Button – For saving BYTE Array to MP3.
The Button has been assigned with a Click event handler.
Namespaces
You will need to import the following namespace.
C#
VB.Net
Saving Byte Array to MP3 using C# and VB.Net
When the Save Button is clicked, the BYTE Array of the sample audio file (MP3) is determined using ReadAllBytes method of the File class.
Then, the BYTE Array is saved to another audio file (MP3) using WriteAllBytes method of File class and the audio file (MP3) is at the specified path.
Finally, the success message is displayed using MessageBox.
C#
private void OnSave(object sender, EventArgs e)
{
// Converting the file to Byte Array.
byte[] bytes = File.ReadAllBytes(@"E:\Sample.mp3");
// Saving Byte Array to mp3.
File.WriteAllBytes(@"D:\Welcome.mp3", bytes);
// Showing message.
MessageBox.Show("File have been saved.");
}
VB.Net
Private Sub OnSave(sender As Object, e As EventArgs) Handles btnSave.Click
' Converting the file to Byte Array.
Dim bytes As Byte() = File.ReadAllBytes("E:\Sample.mp3")
' Saving Byte Array to mp3.
File.WriteAllBytes("D:\Welcome.mp3", bytes)
' Showing Message.
MessageBox.Show("File have been saved.")
End Sub
Screenshot
Downloads