openFile.Close() not closing!

DiverDan

Well-known member
Joined
Jan 16, 2003
Messages
645
Location
Sacramento, CA
User Rank
*Experts*
I am calling a LoadListview sub to open and Deserialize a binary file. The openfile dialog is as follows:

Code:
OpenFileDialog1.InitialDirectory = "C:\"
                OpenFileDialog1.Filter = "Electric Calculator (*.elc)|*.elc|Binary (*.bin)|*.bin"
                OpenFileDialog1.DefaultExt = "elc"
                OpenFileDialog1.AddExtension = True
                If OpenFileDialog1.ShowDialog() = DialogResult.Cancel Then Exit Sub
                worksheetName = OpenFileDialog1.FileName
                LoadListview(OpenFileDialog1.FileName)

and the LoadListview sub is:

Code:
    Sub LoadListview(ByVal fname As String)
        Dim formatter As New BinaryFormatter()
        Dim openFile As FileStream
        openFile = File.Open(fname, FileMode.Open)
        Dim ListViewItems As New ArrayList()
        ListViewItems = CType(formatter.Deserialize(openFile), ArrayList)
        Dim itm As Integer
        lvData.Items.Clear()
        Dim lvItem As ListViewItem
        For itm = 0 To ListViewItems.Count - 1
            lvItem = New ListViewItem()
            lvItem = ListViewItems(itm)
            lvData.Items.Add(lvItem)
        Next
        openFile.Close()
    End Sub

openFile.Close() is not closing and prevents any other files to be opened and displayed. Why is openFile.Close() not closing?

Thanks
 
Last edited by a moderator:
Never mind, I found the problem.

I was accessing other rtf and picture files using the System.Environment.CurrentDirectory method, which does work, but not in this case.

The Application.StartupPath method solved the problem.

Thanks
 
Back
Top