Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]Welcome to DevExpress .NET Documentation
[Expand]WinForms Controls
[Collapse]ASP.NET Controls and MVC Extensions
 [Expand]Prerequisites
 [Expand]What's Installed
 [Collapse]Common Concepts
  [Expand]Web.config Modifications
  [Expand]Callback Exception Handling
  [Expand]Client-Side Functionality
  [Expand]Cookies Support
  [Expand]Appearance Customization - Theming
   Icon Collection
  [Expand]Performance Optimization
  [Expand]CSS Image Sprites
   Supported Document Types
  [Expand]Accessibility Support
   Right to Left Support
   HTML Encoding
   Binary Storage Configuration
  [Expand]SharePoint Support
   Mobile Support
  [Collapse]Office Document Management
   [Collapse]Document Loading
     Opening Documents
     Sharing Documents
   [Expand]Document Saving
    Document Hibernation
   Cloud Storage Account Management
  [Expand]Web Farm and Web Garden Support
 [Expand]ASP.NET WebForms Controls
 [Expand]ASP.NET MVC Extensions
 [Expand]Localization
 [Expand]Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Opening Documents

This topic describes how to open and reopen documents within DevExpress office controls.

Expanded Open Methods

The method signatures might differ from the platform-specific controls (such as WebForms or MVC), but they have similar common concepts. Office controls expose the Open methods of the following types:

  • Open (string pathToDocument) method

    The method loads a document from the server's file system. A document is loaded into the server's memory with the DocumentId value taken from the pathToDocument argument when it is opened for the first time.

    If the document specified by pathToDocument has already been loaded and is in the DocumentManager's list of open documents, the method attaches the office control to the open document and reopens its model (with all unsaved changes) stored in the server's memory.

  • Open (IDocumentInfo documentInfo) method

    This method opens a document from the DocumentManager's list of open documents. The IDocumentInfo interface specifies the document to be opened in the office control. This interface exposes a unique DocumentId that identifies which document to open.
    Since only opened documents that are maintained by DocumentManager are defined using IDocumentInfo, the method can only be used to attach the office control to this preloaded document and reopen its model from server memory. Use the DocumentManager.FindDocument or DocumentManager.GetAllDocuments method to obtain the IDocumentInfo.

  • Open (string documentId, Func contentAccessor) method

    This method loads a document from a custom storage and opens it within the office control. You can get the document from a stream or a byte array using the corresponding contentAccessor parameter. Specify the documentId value to identify the document in the internal dictionary (in DocumentManager).

    If the specified documentId parameter is not unique within all open documents, the method reopens the previously loaded document with the same documentId key.

    If you open a document from a database, it is good practice to use a data row's key value as the documentId parameter. If you prefer not to use the database row key is, generate a new unique identifier using the Guid structure.

    Below is an example that uses the Open method to load a document from a stream:

    The following example uses the Open method to load a document from a byte array:

Expanded Opening Documents as Templates

Certain document management scenarios require that end-users open their own copies of a document from its initial state. In this case, the original version of a document is used as a template. Each user can obtain their own copy and modify it independently from other users who open the same template.

To implement this scenario, each end-user should have a copy of an initial document with a unique DocumentId value – via the Open methods, exposing the definite documentId parameter (such as Open(string documentId, Func contentAccessor) or Open(string documentId, Func<byte[]> contentAccessor) ).

Note

Do not use the Open (string pathToDocument) method for this scenario, because it always opens a single document that has the same DocumentId specified by the pathToDocument parameter.

Note that it might be useful to store the DocumentId values of each user document copy, which allows end-users to work with documents after a user closes or reopens the application page in a browser.

The example below demonstrates a stream approach, which uses the Open method to open a file system document as a template:

The following example demonstrates a byte array approach, which uses the Open method to open a file system document as a template:

Expanded See Also

Is this topic helpful?​​​​​​​