Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
The System.IO namespace provides several classes that allow for various actions, such as reading and writing, to be performed on files, directories, and streams. For more information, see File and Stream I/O.
To do this... | See the example in this topic... |
---|---|
Create a text file | File.CreateText method FileInfo.CreateText method File.Create method FileInfo.Create method |
Write to a text file | How to: Write Text to a File How to: Write a Text File (C++/CLI) |
Read from a text file | How to: Read Text from a File |
Append text to a file | How to: Open and Append to a Log File File.AppendText method FileInfo.AppendText method |
Rename or move a file | File.Move method FileInfo.MoveTo method |
Delete a file | File.Delete method FileInfo.Delete method |
Copy a file | File.Copy method FileInfo.CopyTo method |
Get the size of a file | FileInfo.Length property |
Get the attributes of a file | File.GetAttributes method |
Set the attributes of a file | File.SetAttributes method |
Determine whether a file exists | File.Exists method |
Read from a binary file | How to: Read and Write to a Newly Created Data File |
Write to a binary file | How to: Read and Write to a Newly Created Data File |
Retrieve a file name extension | Path.GetExtension method |
Retrieve the fully qualified path of a file | Path.GetFullPath method |
Retrieve the file name and extension from a path | Path.GetFileName method |
Change the extension of a file | Path.ChangeExtension method |
To do this... | See the example in this topic... |
---|---|
Access a file in a special folder such as My Documents | How to: Write Text to a File |
Create a directory | Directory.CreateDirectory method FileInfo.Directory property |
Create a subdirectory | DirectoryInfo.CreateSubdirectory method |
Rename or move a directory | Directory.Move method DirectoryInfo.MoveTo method |
Copy a directory | How to: Copy Directories |
Delete a directory | Directory.Delete method DirectoryInfo.Delete method |
See the files and subdirectories in a directory | How to: Enumerate Directories and Files |
Find the size of a directory | System.IO.Directory class |
Determine whether a directory exists | Directory.Exists method |
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowTraining
Module
Work with files and directories in a .NET app - Training
Learn how to use .NET, C#, and System.IO to work with directories, paths, files, and the file system.
Documentation
How to: Read and write to a newly created data file - .NET
Learn how to read and write to a newly created data file in .NET using the System.IO.BinaryReader and System.IO.BinaryWriter classes.
Learn the basics of file and stream I/O, which is the transfer of data either to or from a storage medium, in .NET.
In this article, see examples of how to read text synchronously or asynchronously from a text file, using the StreamReader class in .NET for desktop apps.