Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
CreateFromFile Method (String, FileMode, String, Int64)

MemoryMappedFile.CreateFromFile Method (String, FileMode, String, Int64)

.NET Framework 4.6 and 4.5

Creates a memory-mapped file that has the specified access mode, name, and capacity from a file on disk.

Namespace:  System.IO.MemoryMappedFiles
Assembly:  System.Core (in System.Core.dll)

static member CreateFromFile : 
        path:string * 
        mode:FileMode * 
        mapName:string * 
        capacity:int64 -> MemoryMappedFile


Type: System.String

The path to the file to map.

Type: System.IO.FileMode

Access mode; can be any of the FileMode enumeration values except Append.

Type: System.String

A name to assign to the memory-mapped file.

Type: System.Int64

The maximum size, in bytes, to allocate to the memory-mapped file. Specify 0 to set the capacity to the size of the file on disk.

Return Value

Type: System.IO.MemoryMappedFiles.MemoryMappedFile
A memory-mapped file that has the specified characteristics.


path is an empty string, contains only white space, or has one or more invalid characters, as defined by the Path.GetInvalidFileNameChars method.


path refers to an invalid device.


mapName is an empty string.


mode is Append.


path or mapName is a null reference (Nothing in Visual Basic).


capacity is greater than the size of the logical address space.


capacity is less than zero.


capacity is less than the file size (but not zero).


capacity is zero, and the size of the file on disk is also zero.


An I/O error occurred.


path exceeds the maximum length defined by the operating system. In Windows, paths must contain fewer than 248 characters, and file names must contain fewer than 260 characters.


The caller does not have the required permissions for the file.

The mode parameter pertains to the source file on disk.

If capacity is larger than the size of the file on disk, the file on disk is increased to match the specified capacity even if no data is written to the memory-mapped file. To prevent this from occurring, specify 0 (zero) for the default capacity, which will internally set capacity to the size of the file on disk.

.NET Framework

Supported in: 4.6, 4.5, 4

.NET Framework Client Profile

Supported in: 4
© 2015 Microsoft