You are currently browsing legacy 3.0 version of documentation. Click here to switch to the newest 4.2 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

Opening a session

The OpenAsyncSession method is the only way to retrieve the IAsyncFilesSession object from the FilesStore.

Syntax

There are three overloads of the OpenAsyncSession method:

// Open a session for a 'default' file system configured in 'FilesStore'
IAsyncFilesSession OpenAsyncSession();

// Open a session for a specified file system
IAsyncFilesSession OpenAsyncSession(string filesystem);

// Open a session for a specified file system with custom API Key / Credentials
IAsyncFilesSession OpenAsyncSession(OpenFilesSessionOptions sessionOptions);

The first method is an equivalent of:

store.OpenAsyncSession(new OpenFilesSessionOptions()
{
	FileSystem = store.DefaultFileSystem
});

The second overload is an equivalent of:

store.OpenAsyncSession(new OpenFilesSessionOptions()
{
	FileSystem = filesystem
});

Parameters
sessionOptions OpenFilesSessionOptions Options containing information such as the name of a file system on which the session will work and the credentials to use.
Return Value
IAsyncFilesSession The session object that implements the IAsyncFilesSession interface.

Example

using (IAsyncFilesSession session = store.OpenAsyncSession())
{
	// code here
}

Always dispose the session

The session needs to allocate additional resources internally. You need to invoke the Dispose method on it or wrap the session object into the using statement.