Saturday, December 19, 2015

file related problem in C# FileStream access

in one of my program in C#, I got this 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 research and find some clues from internet. listed them here for future reference. the reason is that following message:
Do not use the following reserved names for the name of a file:
CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9. Also avoid these names followed immediately by an extension; for example, NUL.txt is not recommended. For more information, see Namespaces.

  1. workaround for FileStream bug?
  2. Exception: Filestream will not open win32 devices.... don't use \ "\\\.\\\" in the path
  3. Writing a File that has the Name of a Device
  4. Gaining access to the File Allocation Table in C# or any other direct drive access
  5. Naming Files, Paths, and Namespaces

No comments:

Post a Comment