Click here to Skip to main content
15,920,603 members
Articles / Programming Languages / C#

Microsoft Reserved Words that Cannot be Used as File Name

Rate me:
Please Sign up or sign in to vote.
4.41/5 (8 votes)
19 Dec 2015CPOL 11.3K   7   4
A tip that you need to know when you want to create many file names


I am writing a small tool that needs to create lot of files with different names(9000+). Then I got one strange error message:

System.ArgumentException occurred HResult=-2147024809 Message=FileStream will not open 
Win32 devices such as disk partitions and tape drives. Avoid use of "\\.\" in the path. 
Source=mscorlib StackTrace: at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, 
Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, 
SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, 
Boolean useLongPath, Boolean checkHost) InnerException:  

I did some research and found out the reason. I have listed the results here to share with you. Hope it will save you some time in the future.


Microsoft has reserved the following words that cannot be used as file names:

CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9.?



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Software Developer
United States United States
turns good thoughts into actions...

Comments and Discussions

Suggestionalso... Pin
John Torjo22-Dec-15 5:00
professionalJohn Torjo22-Dec-15 5:00 
QuestionEven more to the point, they cannot appear as part of a file name. Pin
hpcoder221-Dec-15 12:53
hpcoder221-Dec-15 12:53 
GeneralMy vote of 5 Pin
David A. Gray19-Dec-15 20:52
David A. Gray19-Dec-15 20:52 
GeneralRe: My vote of 5 Pin
Southmountain20-Dec-15 2:34
Southmountain20-Dec-15 2:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.