> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ExportToMemory Method of the Project Object

This method allows you to save results of project processing into memory, presented as a virtual file system. You can save the results for all the documents of the project or specify particular batches to export results from.

Use the [**ExportParams**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/exportparams.md) object to set the export settings. Note, however, that the values of the [**RootPath**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/fileexportparams.md#rootpath) property of the [**FileExportParams**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/fileexportparams.md) object and the [**Path**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/imageexportparams.md#path) property of the [**ImageExportParams**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/imageexportparams.md) object will be ignored. Instead, the Export and Images directories relative to the root of the virtual file system will be used as the folders for output files. Inside the Export and Images directories, you can have other subfolders, defined by the [**FileNamePattern**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/fileexportparams.md#filenamepattern) property of the **FileExportParams** object and the [**Prefix**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/imageexportparams.md#prefix) property of the **ImageExportParams** object.

Note that you can configure multiple export profiles (a set of settings that determines what is done with processed data) with the help of the [**IExportProfiles::AddNew**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/exportprofiles-addnew.md) method, in which case all appropriate export profiles for export to memory are used in turn.

> [!NOTE]
>
> Only export profiles with the EDT\_File value (export to file) of the [**DestinationType**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/exportparams.md#destinationtype) property are supported for exporting to memory. Export profiles with another destination value are ignored.

## Syntax

```vb Visual Basic .NET theme={null}
Sub ExportToMemory( _
  BatchIds As IntsCollection, _
  ExportParams As ExportParams _
) As VirtualFileSystemNode
```

```cpp C++ theme={null}
HRESULT ExportToMemory(
  IIntsCollection* BatchIds,
  IExportParams*   ExportParams,
  IVirtualFileSystemNode** Result
);
```

## Parameters

**BatchIds**

\[in] This parameter refers to the [**IntsCollection**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/intscollection.md) object that contains a set of identifiers of the batches to export results from. This parameter is optional and may be set to 0, in which case export is performed for all the documents of the project.

**ExportParams**

\[in] This parameter refers to the [**ExportParams**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/exportparams.md) object that contains parameters of export. This parameter may be 0, in which case for each document the export parameters of the corresponding Document Definition are used.

> [!NOTE]
>
> If there is no corresponding Document Definition, the export parameters of the [IBatchTypeParams::ExportParamsForUnknownDocuments](https://docs.abbyy.com/flexi-capture/sdk/api-reference/batchtypeparams.md#exportparamsforunknowndocuments) property are used. If there is no batch type, the export parameters of the [IProjectProperties::ExportParamsForUnknownDocuments](https://docs.abbyy.com/flexi-capture/sdk/api-reference/projectproperties.md#exportparamsforunknowndocuments) property are used.

**Result**

\[out, retval] A pointer to the [**IVirtualFileSystemNode**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/virtualfilesystemnode.md)**\*** object that receives the results of the exported documents.

## Return values

This method has no specific return values. It returns the [standard return values of ABBYY FlexiCapture SDK functions](https://docs.abbyy.com/flexi-capture/sdk/api-reference/errorcodes.md).

## Samples

> [accordion] C# code
>
> ```csharp theme={null}
> // Custom IWriteStream interface implementation
> // allows you to get a file data
> class SampleWriteStream : FCEngine.IWriteStream, IDisposable
> {
>     // Open a file by its name
>     public SampleWriteStream(string fileName)
>     {
>         stream = File.Open(fileName, FileMode.OpenOrCreate, FileAccess.Write);
>     }
>
>     // The callback method implementation: write a file content
>     // The method should not throw exceptions
>     public void Write(byte[] data)
>     {
>         try
>         {
>              stream.Write(data, 0, data.Length);
>         } catch (Exception)
>         {
>             // Process the exception
>         }
>     }
>
>     public void Dispose()
>     {
>         stream.Close();
>     }
>
>     FileStream stream;
> }
>
> // Walk through the virtual file system tree
> // for writing nodes
> void WriteVfs(IVirtualFileSystemNode vfsNode, string pathPrefix = @".\"
> {
>     string path = Path.Combine(pathPrefix, vfsNode.Name)
>
>     if (vfsNode.IsDirectory)
>     {
>         Directory.CreateDirectory(path);
>         // The directory may have children
>         foreach (IVirtualFileSystemNode childNode in vfsNode.ChildItems)
>         {
>             // Write a subtree
>             WriteVfs(childNode, path);
>         }
>     }
>     else
>     {
>         using (SampleWriteStream writeStream = new SampleWriteStream(path))
>         {
>             // Obtain the file's content
>             vfsNode.SaveToStream(writeStream);
>         }
>     }
> }
>
> // Process the images for export to memory scenario
> void ProcessImages()
> {
>     // Set up the project...
>     // ...
>
>     // You can either export with the default parameters
>     // of the corresponding Document Definition,
>     // or use the custom parameters (per batch or per each document)
>     IExportParams exportParams = engine.CreateExportParams(ExportDestinationTypeEnum.EDT_File);
>     // Set up the export parameters
>     // RootPath property of fileExportParams is not set as it will be ignored anyway
>     IFileExportParams fileExportParams = exportParams.FileExportParams;
>     fileExportParams.FileNamePattern = @"<Batch>\<DocumentDefinition>\<Identifier>";
>     fileExportParams.FileFormat = FileExportFormatEnum.FEF_XLS;
>     fileExportParams.ExportOriginalImages = true;
>
>     // Perform export to memory
>     // The export results have a tree structure and
>     // are represented by the root node of the tree
>     IVirtualFileSystemNode vfsRootNode = project.ExportToMemory(null, exportParams);
>     // Process the exported data, for example, write the export results
>     WriteVfs(vfsRootNode);
>     // Forcibly release memory occupied for the export results,
>     // after that the export data is no more accessible,
>     // and the root node with all child nodes become unavailable for operations
>     Debug.Assert(vfsRootNode.IsRoot);
>     vfsRootNode.ReleaseMemory();
>
>     // Finish the processing cycle, closing the project...
> }
> ```

## See also

[**Project**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/project.md)
