GdPicture.NET.14
GdPicture14 Namespace / GdViewer Class / DisplayFromStream Method / DisplayFromStream(Stream,String,String) Method
A System.IO.Stream object. This object must be properly initialized before it can be sent into this method and it must be disposed of by the user as well.
The password to be used to decrypt the PDF document, if that is stored in the Stream parameter, allowing the control to read its content. Use the empty string to allow the control to automatically prompts users to enter a correct password and also for files with no encryption.
The file name of the document, that is stored in the Stream parameter, for example myfile.tif. The toolkit will automatically recognize the document format based on the file name to be able to display the required file.
Example





In This Topic
DisplayFromStream(Stream,String,String) Method
In This Topic
Loads a document from an instantiated Stream object according to what you have specified and subsequently displays it in the GdViewer control. The document previously displayed in the control will automatically close.

This method is useful for encrypted PDF documents, as you are allowed to enter a password to decrypt the document for reading its content. It is also very useful for files, that have no header information in their internal structure, like text files or .svg files, as you can specify their file name to allow the toolkit with certainty to recognize the document format of the file for display.

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.

Syntax
'Declaration
 
Public Overloads Function DisplayFromStream( _
   ByVal Stream As Stream, _
   ByVal Password As String, _
   ByVal FileName As String _
) As GdPictureStatus
public GdPictureStatus DisplayFromStream( 
   Stream Stream,
   string Password,
   string FileName
)
public function DisplayFromStream( 
    Stream: Stream;
    Password: String;
    FileName: String
): GdPictureStatus; 
public function DisplayFromStream( 
   Stream : Stream,
   Password : String,
   FileName : String
) : GdPictureStatus;
public: GdPictureStatus DisplayFromStream( 
   Stream* Stream,
   string* Password,
   string* FileName
) 
public:
GdPictureStatus DisplayFromStream( 
   Stream^ Stream,
   String^ Password,
   String^ FileName
) 

Parameters

Stream
A System.IO.Stream object. This object must be properly initialized before it can be sent into this method and it must be disposed of by the user as well.
Password
The password to be used to decrypt the PDF document, if that is stored in the Stream parameter, allowing the control to read its content. Use the empty string to allow the control to automatically prompts users to enter a correct password and also for files with no encryption.
FileName
The file name of the document, that is stored in the Stream parameter, for example myfile.tif. The toolkit will automatically recognize the document format based on the file name to be able to display the required 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
Just to remind you that you can use the empty string as a Password parameter to allow the control to automatically pop up a dialog box for entering a correct password if the source document is encrypted PDF file and also for files with no encryption.

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

Example
How to display a simple textfile from a stream.
'We assume that the GdViewer1 control has been properly integrated.
Dim file As System.IO.Stream = New System.IO.FileStream("text.txt", System.IO.FileMode.Open)
If GdViewer1.DisplayFromStream(file, "", "text.txt") = GdPictureStatus.OK Then
    'Do your stuff here.
Else
    MessageBox.Show("This file can't be displayed. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.DisplayFromStream")
End If
file.Dispose()
//We assume that the GdViewer1 control has been properly integrated.
System.IO.Stream file = new System.IO.FileStream("text.txt", System.IO.FileMode.Open);
if (GdViewer1.DisplayFromStream(file, "", "text.txt") == GdPictureStatus.OK)
{
    //Do your stuff here.
}
else
{
    MessageBox.Show("This file can't be displayed. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.DisplayFromStream");
}
file.Dispose();
See Also