C# Reserved FilenamesDevelop a class that checks for reserved file names. Prevent errors from incorrect file names.
Reserved file names cannot be used. We can detect these names in strings in a C# program. This ensures we do not generate an invalid file name.
Some examples. Some reserved file names are CON.txt, PRN.doc and nul.exe. If we need to generate file names, we can test to ensure we do not choose a reserve done.
Reserved list. Here is a list of file names that cannot be used in Windows. On other operating systems like Linux and macOS these file names are not reserved.
Example code. This issue can occur when a Windows server tries to serve a file such as PRN.aspx, which is dynamically generated. This code can detect such invalid file names.
A summary. We saw a useful method—it can detect the invalid file names that Windows reserves. This includes all the Windows server environments, such as IIS.