Back to Devexpress

DocumentManager.CloseDocument(String) Method

aspnet-devexpress-dot-web-dot-office-dot-documentmanager-dot-closedocument-x28-system-dot-string-x29.md

latest6.2 KB
Original Source

DocumentManager.CloseDocument(String) Method

Closes a document with the specified ID.

Namespace : DevExpress.Web.Office

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public static void CloseDocument(
    string documentId
)
vb
Public Shared Sub CloseDocument(
    documentId As String
)

Parameters

NameTypeDescription
documentIdString

The unique identifier of a document.

|

Remarks

Office controls (ASPxSpreadsheet and ASPxRichEdit) do not close a document when you open another document or even when you leave a page with the control. The document storage retains the document until it is hibernated and then removed from the memory after a dispose timeout. If the hibernation is disabled, the document remains in the storage until IIS process recycling occurs.

Call the CloseDocument methods to close a document explicitly:

csharp
DocumentManager.CloseDocument(ASPxSpreadsheet1.DocumentId);
vb
DocumentManager.CloseDocument(ASPxSpreadsheet1.DocumentId)

Call the CloseAllDocuments() method to close all open documents.

csharp
DocumentManager.CloseAllDocuments();
vb
DocumentManager.CloseAllDocuments()

When you close a document, DocumentManager closes it for all users who work on the document. It can cause NullReferenceException and “Your session has expired” errors. To avoid these errors, close unshared documents only.

The following code snippets (auto-collected from DevExpress Examples) contain references to the CloseDocument(String) 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.

asp-net-web-forms-richedit-work-with-database/CS/ASPxRichEdit_Binding/Default.aspx.cs#L22

csharp
if(!string.IsNullOrEmpty(EditedDocuemntID)) {
    DocumentManager.CloseDocument(DocumentManager.FindDocument(EditedDocuemntID).DocumentId);
    EditedDocuemntID = string.Empty;

asp-net-web-forms-spreadsheet-work-with-database/CS/ASPxSpreadsheetBinding/Default.aspx.cs#L18

csharp
if(!string.IsNullOrEmpty(EditedDocumentID)) {
    DocumentManager.CloseDocument(DocumentManager.FindDocument(EditedDocumentID).DocumentId);
    EditedDocumentID = string.Empty;

asp-net-web-forms-spreadsheet-download-file-on-custom-ribbon-item-click/CS/ASPxSpreadsheetBinding/Default.aspx.cs#L63

csharp
void CloseSpreadsheetDocument() {
    DocumentManager.CloseDocument(DocumentManager.FindDocument(EditedDocuemntID).DocumentId);
    EditedDocuemntID = string.Empty;

asp-net-web-forms-richedit-work-with-database/VB/ASPxRichEdit_Binding/Default.aspx.vb#L32

vb
If Not String.IsNullOrEmpty(EditedDocuemntID) Then
    Call DocumentManager.CloseDocument(DocumentManager.FindDocument(EditedDocuemntID).DocumentId)
    EditedDocuemntID = String.Empty

asp-net-web-forms-spreadsheet-work-with-database/VB/ASPxSpreadsheetBinding/Default.aspx.vb#L28

vb
If Not String.IsNullOrEmpty(EditedDocumentID) Then
    Call DocumentManager.CloseDocument(DocumentManager.FindDocument(EditedDocumentID).DocumentId)
    EditedDocumentID = String.Empty

asp-net-web-forms-spreadsheet-download-file-on-custom-ribbon-item-click/VB/ASPxSpreadsheetBinding/Default.aspx.vb#L70

vb
Private Sub CloseSpreadsheetDocument()
    Call DocumentManager.CloseDocument(DocumentManager.FindDocument(EditedDocuemntID).DocumentId)
    EditedDocuemntID = String.Empty

See Also

Spreadsheet Document Management

RichEdit Document Management

DocumentManager Class

DocumentManager Members

DevExpress.Web.Office Namespace