Skip to main content
A newer version of this page is available. .

ASPxSpreadsheet.Open(String, DocumentFormat, Func<Stream>) Method

Opens a document specified by a stream.

Namespace: DevExpress.Web.ASPxSpreadsheet

Assembly: DevExpress.Web.ASPxSpreadsheet.v18.2.dll

Declaration

public void Open(
    string documentId,
    DocumentFormat format,
    Func<Stream> contentAccessorByStream
)

Parameters

Name Type Description
documentId String

A string value that uniquely identifies the document to open (the document’s DocumentId).

format DocumentFormat

A DocumentFormat object specifying the document format.

contentAccessorByStream Func<Stream>

A method delegate to obtain a stream from which to open the document.

Remarks

This method tries to find the specified document in a list of already opened documents maintained by the DocumentManager. If the document is found, its instance is opened in the Spreadsheet. If the specified document has not been found in the opened documents, a delegate method specified by the contentAccessorByStream parameter is called. It allows you to manually obtain a steam from which to open a document (for instance, to load a document from a database).


private void CustomDocumentOpening() {
    var uniqueDocumentId = GetUniqueDocumentId();

    // Open a document from a stream 
    using (var stream = GetStreamFromCustomDocumentStorage()) {
        ASPxSpreadsheet1.Open(uniqueDocumentId, DocumentFormat.Xlsx, () => stream);
    }
}

private string GetUniqueDocumentId() {
    throw new NotImplementedException();
    // Obtain a previously saved DocumentId (for instance, from a database, if you have previously saved it there): 
    // return GetDocumentIdFromDatabase(); 
    // or 
    // Create a new unique identifier: 
    // return Guid.NewGuid().ToString(); 
}


private FileStream GetStreamFromCustomDocumentStorage() {
    throw new NotImplementedException();
    // Provide your custom logic to obtain a document (for instance, from a database) 
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Open(String, DocumentFormat, Func<Stream>) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also