Meziantou
Read post

Reserved filenames on Windows (CON, PRN, AUX, NUL...)

Windows reserves certain filenames (CON, PRN, AUX, NUL, COM0-COM9, LPT0-LPT9) inherited from DOS for backward compatibility. These names are case-insensitive and cannot be used with extensions either. While Win32 APIs enforce this restriction, the underlying file systems (NTFS, FAT32, ReFS) do not — meaning WSL or the `\?\` path prefix can bypass it. In .NET, accessing such filenames via standard System.IO APIs throws an IOException, and Path.GetInvalidFileNameChars() does not flag them. Using the `\?\` prefix in .NET allows creating, reading, and deleting files with reserved names. The Meziantou.Framework.FullPath NuGet package handles this automatically by applying the prefix internally when reserved names are detected.

    #windows#.net#c#
Feb 23•4m read time•From meziantou.net
Post cover image
Table of contents
## Win32 API vs. File System## Creating reserved files with WSL## Accessing reserved files in .NET## Bypassing the restriction## Additional resources
5K Impressions
Meziantou's image
Meziantou

Meziantou's resource offers insights, tutorials, and resources for software developers and IT profes...

18 Followers

•

104 Upvotes

Would you recommend this post?

Copy link
WhatsApp
Facebook
X
New Squad
  • © 2026 Daily Dev Ltd.
  • Guidelines
  • Explore
  • Tags
  • Sources
  • Squads
  • Leaderboard