Troubleshooting: Reading from and Writing to Text Files
This topic discusses common problems encountered when working with text files and suggests an approach to each.
Common Problems
The most common issues encountered when working with text files include security exceptions, file encodings, or invalid paths.
Security Exceptions
A SecurityException is thrown when a security error occurs. This is often a result of the user lacking necessary permissions, which may be solved by adding permissions or working with files in isolated storage. For more information, see Troubleshooting Exceptions: System.Security.SecurityException and Isolated Storage.
File Encodings
File encodings, also known as character encodings, specify how to represent characters when text processing. Unexpected characters in a text file may result from incorrect encoding. For most files, one encoding may be preferable over another in terms of which language characters it can or cannot handle, although Unicode is usually preferred. For more information, see File Encodings and Encoding.
Incorrect Paths
When parsing file paths, particularly relative paths, it is easy to supply the wrong data. Many problems can be corrected by making sure you are supplying the correct path. For more information, see How to: Parse File Paths in Visual Basic.
See Also
Concepts
Parsing Text Files with the TextFieldParser Object