Click or drag to resize

DocumentViewerDocumentSource Property

Gets or sets the document source to load and display. This is an alternative to Document property. When you don't have a file on disk and implementing IDocumentHandler interface is not convenient, you can use this property to load documents from a stream or a byte array. Note that your stream or byte array will be copied to the cache folder if not already exists when you load via DocumentSource because DocumentViewer needs to access your document out of the context of the host page (i.e. serialization is needed).

Namespace:  GleamTech.DocumentUltimate.AspNet.UI
Assembly:  GleamTech.DocumentUltimate (in GleamTech.DocumentUltimate.dll) Version: 5.4.2
Syntax
public DocumentSource DocumentSource { get; set; }

Property Value

Type: DocumentSource
Examples

Load document from a stream:

documentViewer.DocumentSource = new DocumentSource(
    new DocumentInfo("uniqueId", "InputFile.docx"),
    new StreamResult(stream)
);

Initializing a DocumentInfo instance:

// Either provide a file name with extension  
var documentInfo = new DocumentInfo("uniqueId", "InputFile.docx");

// Or specify an explicit document format if you don't have a file name
var documentInfo2 = new DocumentInfo("uniqueId", null, DocumentFormat.Docx);
// Which can also be written as
var documentInfo3 = new DocumentInfo("uniqueId", format: DocumentFormat.Docx);

Load document from a byte array:

documentViewer.DocumentSource = new DocumentSource(
    new DocumentInfo("uniqueId", "InputFile.docx"),
    byteArray
);

Load document from a stream callback:

documentViewer.DocumentSource = new DocumentSource(
    new DocumentInfo("uniqueId", "InputFile.docx"),
    () => GetStreamResult(parameter)
);
public StreamResult GetStreamResult(string parameter)
{
    return new StreamResult(stream);
}

Load document from a byte array callback:

documentViewer.DocumentSource = new DocumentSource(
    new DocumentInfo("uniqueId", "InputFile.docx"),
    () => GetByteArray(parameter)
);
public byte[] GetByteArray(string parameter)
{
    return byteArray;
}
See Also