Description
[I have spent MANY hours and used many references to try to find a way to import a simple text file into a RichTextBox using the ever so inviting and so often cited "RichTextBox1.ReadAllText("C:\Temp\Results.txt")" which dutifully fully fails to even "compile/build/...". The error messages usually complain about not finding the file, even presenting its full "file spec" accurately as "C:\Temp\Results.txt". Yes it is there. Yes I do have the obligatory "Import System.IO" at the top. So I have tried simply moving the Results.txt file into the ...\bin and ...\debug folders where the code runs under VS2022. Tried a few dozen or so ways to reformat the "file spec", eg using "\" in lieu of "", etc with no success. And tried to forgo the apparently wonderful-if-it-actually-worked solution and tried using the StreamReader method to get the data and do the parsing/loading into the RichTextBox the hard but hopefully reliable way. NOPE... The crux seems to revolve around how to accurately describe where the text file is without specifying the drive, e.g. "C:" on which it resides - that pesky ":" that per the aforementioned "rules" is a "no no" - but how can that be?
The "wonderful function" MUST have worked once as it is so frequently cited in references on how to read text file data into a RichTextBox. So maybe it has been emasculated by some change to Windows security feature, e.g I can no longer download file to the folder of my choosing.
In short HELP!!! And thanks in advance if you read this far...
Regards, John W. Lonberger at [email protected]
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
- ID: 28ed0fd1-c981-8b68-dc7c-896264005966
- Version Independent ID: 237d8aed-2839-305d-2c6c-6a0c62bd6298
- Content: How to: Read From Text Files - Visual Basic
- Content Source: docs/visual-basic/developing-apps/programming/drives-directories-files/how-to-read-from-text-files.md
- Product: dotnet-visualbasic
- GitHub Login: @KathleenDollard
- Microsoft Alias: kdollard