Why cant I open file?

vidflix

Member
Joined
Feb 7, 2009
Messages
5
Programming Experience
Beginner
Hi members,

Im having a problem opening my saved files with OpenFileDialog. I point it to the right directory, and filetype no problem, but when i choose the file, and click open, i either get an exception, or it wont do anything. I know this is a basic task, but im quite new to this, and would appreciate any help. Ive included my code below. Not sure what im doing wrong. I have imported the following namespaces as well : System.IO and System.IO.Filestream

Heres the code:
VB.NET:
Private Sub NewOrSavedEpcrOpenSavedEpcrButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewOrSavedEpcrOpenSavedEpcrButton.Click

        Dim v_openFilePath As String = "c:\EPCR\"

        OpenEpcrOpenFileDialog.InitialDirectory = v_openFilePath
        OpenEpcrOpenFileDialog.Filter = "EPCR Files(*.epcr)| *.epcr"

        If OpenEpcrOpenFileDialog.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
            OpenEpcrOpenFileDialog.OpenFile()
        End If


    End Sub

Thanks for your help. Most appreciated.
 
Have you read the MSDN documentation for the OpenFileDialog.OpenFile method? What exactly do you expect to happen when you do this:
VB.NET:
OpenEpcrOpenFileDialog.OpenFile()
That code IS opening the file. It's just that you're not then doing anything with. The contents of the file will not simply appear by magic. It's up to you to read the data the file contains and then use it in whatever way is appropriate. You also need to then close the file again.

Also, System.IO.FileStream is NOT a namespace and you should not be importing it. It's a class. The OpenFile method you're calling returns an instance of that class, i.e. a FileStream object. You are supposed to use that FileStream object to access the contents of the file.
 
Thank you. Ive been reading, but couldnt figure out how it worked. I am a VB.NET newbie. Your explanation has clarified things for me. Thank you. Back to studying :)
 
Back
Top