Imports System.IO
Public Class Form1
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim S() As String = OpenFileDialog1.FileNames
Dim File As String
Dim sr As New IO.FileStream(OpenFileDialog1.FileName, IO.FileMode.Open)
Dim fmt As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
For Each File In S
lstFiles.Items.Add(File)
Next
sr.Close()
End If
End Sub
Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click
If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim sw As New IO.FileStream(SaveFileDialog1.FileName, IO.FileMode.Create)
Dim fmt As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
Dim file As IO.File = CType(fmt.Deserialize(sw), Object)
For Each item As String In lstFiles.Items
file = CType(file.Create(item), Object)
fmt.Serialize(sw, file)
Next
sw.Close()
End If
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
lstFiles.Items.Clear()
End Sub
End Class
So, I can add files to the lstFiles, then when I click btnCreate I enter the filename I want to save it as, then I get the error: "Attempting to deserialize an empty stream."
I'm not even sure if this is the proper way to go about this and wanted to see if there was a better way, or if there is a way to fix the code above to do this.

New Topic/Question
Reply




MultiQuote




|