WebDocumentViewerConfigurationBuilder.UseFileDocumentStorage(String, StorageSynchronizationMode) Method

Specifies a path and synchronization mode for the report document's file storage.

Namespace: DevExpress.AspNetCore.Reporting

Assembly: DevExpress.AspNetCore.Reporting.v18.2.dll

Declaration

public WebDocumentViewerConfigurationBuilder UseFileDocumentStorage(
    string workingDirectory,
    StorageSynchronizationMode storageSynchronizationMode
)
Public Function UseFileDocumentStorage(
    workingDirectory As String,
    storageSynchronizationMode As StorageSynchronizationMode
) As WebDocumentViewerConfigurationBuilder

Parameters

Type Name Description
String workingDirectory

Specifies a path to the directory where documents should be stored.

StorageSynchronizationMode storageSynchronizationMode

Specifies a synchronization mode for the file storage.

Returns

Type Description
WebDocumentViewerConfigurationBuilder

A WebDocumentViewerConfigurationBuilder that can be used to further configure the Web Document Viewer services.

To display a report, the Web Document Viewer generates a report document. By default, documents are stored in a memory cache. This is not a stable storage because the application pool can be recycled when the memory usage reaches a specified limit, idle session closes or a scheduled cache cleaning runs. This all leads to the document's deletion from the memory cache and the inability of the Document Viewer to display the document. To avoid this, use a file storage for report documents. Call the UseFileDocumentStorage method to specify a path to the directory that the Document Viewer will use to get a document when the memory cache is empty.

Use the UseFileDocumentStorage(String, StorageSynchronizationMode) method overload to specify the InterProcess synchronization mode if you use Web Farms or Garden. By default, the InterThread mode is set.

The following code demonstrates how to use the UseFileDocumentStorage method, to specify a path and synchronization mode for the Document Viewer's file storage.

using DevExpress.XtraReports.Web.WebDocumentViewer;
using DevExpress.AspNetCore;
using DevExpress.AspNetCore.Reporting;
//... 

public class Startup {
//... 
    string contentRootPath;
    public Startup(IHostingEnvironment env) {
        contentRootPath = env.ContentRootPath;
        //...
    };
    public void ConfigureServices(IServiceCollection services) {
        services.AddDevExpressControls();
        services.AddMvc(); 

        services.ConfigureReportingServices(configurator => {
            configurator.ConfigureWebDocumentViewer(viewerConfigurator => {
                viewerConfigurator.UseFileDocumentStorage(System.IO.Path.Combine(contentRootPath, "DocumentStorage"),StorageSynchronizationMode.InterProcess);
            });
        });        
    }
//...    
}
Note

If a viewed report includes interactive features, the Document Viewer uses the report's instance to recreate the document. By default, the report instance is stored in memory. Specify a file storage to avoid problems with application pool recycling. For this purpose, use the UseFileReportStorage method.

According to the time settings specified in the CacheCleanerSettings and StorageCleanerSettings classes, the default cleaner service periodically checks if the cache and file storage contain documents whose lifetime exceeds certain amount of time. If such documents are found, they are deleted. Call the UseEmptyStoragesCleaner() method to register an empty storage cleaner instead of the default one, so that documents are not removed automatically.

To force cache clearing, use the following code (where "viewer" corresponds to the client instance name of the Document Viewer). Note that due to Garbage Collector specifics, disposing of a report does not guarantee immediate memory release.

viewer.close();

See Also