System.IO.File.Create Method

Creates or overwrites a file in the specified path.

Syntax

public static FileStream Create (string path)

Parameters

path
The path and name of the file to create.

Returns

A System.IO.FileStream that provides read/write access to the file specified in path.

Exceptions

TypeReason
System.Security.SecurityExceptionThe caller does not have the required permission.
ArgumentException path is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters.
ArgumentNullException path is null.
System.IO.DirectoryNotFoundExceptionThe directory information specified in path was not found.
System.IO.IOExceptionAn I/O error occurred while creating the file.
UnauthorizedAccessExceptionThe caller does not have the required permission.
System.IO.PathTooLongExceptionThe length of path or the absolute path information for path exceeds the system-defined maximum length.

Remarks

The System.IO.FileStream object created by this method has a default System.IO.FileShare value of FileShare.None; no other process or code can access the created file until the original file handle is closed.

This method is equivalent to the File.Create(string, int) method overload using the default buffer size.

The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see Directory.GetCurrentDirectory.

If the specified file does not exist, it is created; if it does exist and it is not read-only, the contents are overwritten.

By default, full read/write access to new files is granted to all users. The file is opened with read/write access and must be closed before it can be opened by another application.

For a list of common I/O tasks, see Common I/O Tasks.

Permissions

Requirements

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0