Question DLL Can not open File Dialog?

raford

New member
Joined
Aug 14, 2008
Messages
2
Programming Experience
Beginner
Hi, every body.:D

I am beginner of vb.net programming as well as of being member of this forum.
I tried to make my own class as dll, so that I can import in other project, to use functions.

But problem is :mad: that my class library project says my attempt to open file dialog is error, because it can not understand what OpenFileDialog is actually.

I thought then I need to import some classes, but I can not find any class named OpenFileDialog from any package.

Please help me,kindly. Urgent.

VB.NET:
Public Class Utility
    '*** Show Open File Dialog
    '*** Parameter title : Dialog title : default="Open File"
    '              filter : ex: Text files (*.txt)|*.txt|All files (*.*)|*.*"
    '*** Return file path (if nothing choosen, empty string)

    Public Function getOneFilePathForOpen(Optional ByVal title As String = "Open File", Optional ByVal filter As String = "All files (*.*)|*.*") As String
        getOneFilePathForOpen = ""
        Dim objOpenFileDialog As New OpenFileDialog '(<= Marked as Error)
        '-------------- Set the Open dialog properties
        With objOpenFileDialog
            .Filter = filter
            .FilterIndex = 1
            .Title = title
        End With
        '-------------- If choosen
        If objOpenFileDialog.ShowDialog = Windows('<= Marked as Error).Forms.DialogResult.OK Then
            Try
                getOneFilePathForOpen = My.Computer.FileSystem.ReadAllText( _
                    objOpenFileDialog.FileName)
            Catch fileException As Exception
                Throw fileException
            End Try
        End If
        '--------------- Clear object
        objOpenFileDialog.Dispose()
        objOpenFileDialog = Nothing
    End Function
End Class
 
Last edited:
Documentation tell you where OpenFileDialog Class is:
MSDN said:
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
So you need to reference the assembly and import the namespace.
 
Or call it from the namespace directly:
Dim objOpenFileDialog As New System.Windows.Forms.OpenFileDialog
 
Class Library projects doesn't reference the System.Windows.Forms library by default.
 
So you need to reference the assembly and import the namespace.

Good advice.
So you mean I need to update my reference list so that it would include also OpenFileDialog class?

I will dig document then more and more.
Actually I should not have posted such a question, should I?

I will try more.

Regards.

(And your kind guidance of how to post code is also of great help on me.
Using forum is not so familiar to me in fact.)

Thanks for your trouble to answer,JuggaloBrotha
 
Back
Top