Skip to content

File Reader code snippet violates "the rules" for presented on the same page #33919

Open
@JWL1948

Description

@JWL1948

[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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions