# DocumentBag class

Namespace: [Grasshopper2.UI.Canvas](https://developer.rhino3d.com/api/gh2/namespace/grasshopper2.ui.canvas.md) · Assembly: [Grasshopper2](https://developer.rhino3d.com/api/gh2/assembly/grasshopper2.md)

```cs
public sealed class DocumentBag
```

A collection of documents, one of which is designated as the 'head'.

## Constructors

- [DocumentBag](https://developer.rhino3d.com/api/gh2/type/grasshopper2.ui.canvas.documentbag/ctor.md)

## Properties

- [All](https://developer.rhino3d.com/api/gh2/type/grasshopper2.ui.canvas.documentbag/all.md): Iterate over the heads of all document stacks.
- [Count](https://developer.rhino3d.com/api/gh2/type/grasshopper2.ui.canvas.documentbag/count.md): Gets the number of document stacks.
- [Current](https://developer.rhino3d.com/api/gh2/type/grasshopper2.ui.canvas.documentbag/current.md): Gets the document at the head of the current stack. If no document is currently available, a new, inactive document will be created.
- [Unsaved](https://developer.rhino3d.com/api/gh2/type/grasshopper2.ui.canvas.documentbag/unsaved.md): Iterate over all modified documents.

## Indexers

- [this[]](https://developer.rhino3d.com/api/gh2/type/grasshopper2.ui.canvas.documentbag/item.md): Gets the stack at the given index.

## Methods

- [Contains](https://developer.rhino3d.com/api/gh2/type/grasshopper2.ui.canvas.documentbag/contains.md): Test whether a specific file path is part of this stack. Note that only root files ought to have file paths which means only root files are checked, even if they are not at the head of the stack.
- [CreateLastChanceSaveDialog](https://developer.rhino3d.com/api/gh2/type/grasshopper2.ui.canvas.documentbag/createlastchancesavedialog.md): Return a dialog which contains a list of unsaved documents that cannot be silently restored on next launch (currently: documents that have never been saved). Returns null if no such documents exist. Documents that have a file path are handled via the session record and the autosave flush in [DocumentBag.FlushModifiedAutoSavesForShutdown()](https://developer.rhino3d.com/api/gh2/type/grasshopper2.ui.canvas.documentbag/flushmodifiedautosavesforshutdown.md).
- [FlushModifiedAutoSavesForShutdown](https://developer.rhino3d.com/api/gh2/type/grasshopper2.ui.canvas.documentbag/flushmodifiedautosavesforshutdown.md): Force-flush an up-to-date autosave file to disk for every modified document in the bag that has been saved at least once. Intended to be called during shutdown so that the next launch can reinstate those documents from their autosave files via the session record.
- [Index](https://developer.rhino3d.com/api/gh2/type/grasshopper2.ui.canvas.documentbag/index.md): (2 overloads) Gets the index of the stack containing the specified document.
- [PathSequence](https://developer.rhino3d.com/api/gh2/type/grasshopper2.ui.canvas.documentbag/pathsequence.md): Create a single string which sequences all the paths of all documents which have paths.
- [Pop](https://developer.rhino3d.com/api/gh2/type/grasshopper2.ui.canvas.documentbag/pop.md): Remove a document from this stack. If the popped document is the current one, the next one will be made current. Only documents which are at the heads of their respective stacks can be popped.
- [Push](https://developer.rhino3d.com/api/gh2/type/grasshopper2.ui.canvas.documentbag/push.md): Push a document to this bag and make it current.
- [Queue](https://developer.rhino3d.com/api/gh2/type/grasshopper2.ui.canvas.documentbag/queue.md): Push a document to the end of this stack. If the document is already in the stack, but not at the end, it will *not* be repositioned.
- [RegisterAcceptHandler](https://developer.rhino3d.com/api/gh2/type/grasshopper2.ui.canvas.documentbag/registeraccepthandler.md): Add a callback to a specific document for acceptance handling.
- [RegisterRejectHandler](https://developer.rhino3d.com/api/gh2/type/grasshopper2.ui.canvas.documentbag/registerrejecthandler.md): Add a callback to a specific document for rejection handling.
- [SuspendEvents](https://developer.rhino3d.com/api/gh2/type/grasshopper2.ui.canvas.documentbag/suspendevents.md): Suspend external firing of the [DocumentBag.Changed](https://developer.rhino3d.com/api/gh2/type/grasshopper2.ui.canvas.documentbag/changed.md) event for the lifetime of the returned scope. Internal bookkeeping (such as the active-head [Document.ModifiedChanged](https://developer.rhino3d.com/api/gh2/type/grasshopper2.doc.document/modifiedchanged.md) subscription) still keeps up with the bag's state. When the outermost scope is disposed, a single [DocumentBagEventType.Restored](https://developer.rhino3d.com/api/gh2/type/grasshopper2.ui.canvas.documentbageventtype.md) event is fired so subscribers that build state incrementally can re-sync from scratch. Nestable: only the outermost scope's disposal fires the Restored event.
- [TryOpenDocument](https://developer.rhino3d.com/api/gh2/type/grasshopper2.ui.canvas.documentbag/tryopendocument.md): Load a Grasshopper file into this canvas.

## Events

- [Changed](https://developer.rhino3d.com/api/gh2/type/grasshopper2.ui.canvas.documentbag/changed.md): Raised whenever there's a change to the bag.
- [DocumentModified](https://developer.rhino3d.com/api/gh2/type/grasshopper2.ui.canvas.documentbag/documentmodified.md): Raised when the currently floating document is modified.
