GdPicture.NET.14
GdPicture14 Namespace / GdViewer Class / DisplayFromFile Method / DisplayFromFile(String) Method
The file path of the document to display. Use the empty string to allow the control to prompt users to select a file.

You can subsequently use the GetLastPath method to retrieve the path of the selected file.

Example





In This Topic
DisplayFromFile(String) Method
In This Topic
Loads a document from a file according to a file path you have specified and subsequently displays it in the GdViewer control. The document previously displayed in the control will automatically close.

All document formats currently supported by the toolkit are listed here.

The BeforeDocumentChange and the AfterDocumentChange events are raised just before and right after the document is displayed in the GdViewer control. Both events are only raised if the document has been successfully loaded.

Be aware that the required file is locked for another use by default when loading. To avoid this, set the ForceTemporaryMode property to true before loading to tell the toolkit to use a temporary copy of the specified file.

Syntax
'Declaration
 
Public Overloads Function DisplayFromFile( _
   ByVal FilePath As String _
) As GdPictureStatus
public GdPictureStatus DisplayFromFile( 
   string FilePath
)
public function DisplayFromFile( 
    FilePath: String
): GdPictureStatus; 
public function DisplayFromFile( 
   FilePath : String
) : GdPictureStatus;
public: GdPictureStatus DisplayFromFile( 
   string* FilePath
) 
public:
GdPictureStatus DisplayFromFile( 
   String^ FilePath
) 

Parameters

FilePath
The file path of the document to display. Use the empty string to allow the control to prompt users to select a file.

You can subsequently use the GetLastPath method to retrieve the path of the selected file.

Return Value

A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK. We strongly recommend always checking this status first.
Remarks
Please note that you need to use the ForceTemporaryMode property before loading if you want to avoid locking the specified file.

Just to remind you that you can use the empty string as a FilePath parameter to allow the control to pop up the File Open dialog box. You can later use the GetLastPath method to retrieve the full file path of the selected file.

Likewise, both the BeforeDocumentChange and the AfterDocumentChange events are raised using this method.

Example
How to display a document loaded from a single file.
'We assume that the GdViewer1 control has been properly integrated.
'The File Open dialog box will pop up to select a file.
If GdViewer1.DisplayFromFile("") = GdPictureStatus.OK Then
    MessageBox.Show("The selected file is: " + GdViewer1.GetLastPath(), "GdViewer.DisplayFromFile")
    'Do your stuff here.
    GdViewer1.CloseDocument()
Else
    MessageBox.Show("This file can't be displayed. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.DisplayFromFile")
End If
//We assume that the GdViewer1 control has been properly integrated.
//The File Open dialog box will pop up to select a file.
if (GdViewer1.DisplayFromFile("") == GdPictureStatus.OK)
{
    MessageBox.Show("The selected file is: " + GdViewer1.GetLastPath(), "GdViewer.DisplayFromFile");
    //Do your stuff here.
    GdViewer1.CloseDocument();
}
else
{
    MessageBox.Show("This file can't be displayed. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.DisplayFromFile");
}
See Also