Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

How to: Create a File in Visual Basic

This example creates an empty text file at the specified path using the Create method in the File class.

Dim file As System.IO.FileStream
file = System.IO.File.Create("c:\test.txt")

Use the file variable to write to the file.

If the file already exists, it is replaced.

The following conditions may cause an exception:

A SecurityException may be thrown in partial-trust environments.

The call to the Create method requires FileIOPermission.

An UnauthorizedAccessException is thrown if the user does not have permission to create the file.

Community Additions

© 2015 Microsoft