1

So, I tried loading a file:

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    RichTextBox1.LoadFile("My.Computer.FileSystem.SpecialDirectories.MyDocuments.**1.txt**", RichTextBoxStreamType.PlainText)
End Sub

The 1.txt is errored and I don't know how to make it work when it loads that file (doesn't matter what is written in it just the name "1" is needed) just the location to users documents, load that 1.txt file and show lets say a message box.

As I said before the 1.txt is errored and I don't know how to make it work.

1
  • My.Computer.FileSystem.SpecialDirectories.MyDocuments is a property whose value contains the path of the Documents folder. You need to use that property to get that path and combine that with the file name to create the path of the file. Instead, you are using that property name as a literal string. I think it should be fairly obvious that "My.Computer.FileSystem.SpecialDirectories.MyDocuments.1.txt" is not the actual path of a file on your computer. What you're doing is like if someone ask you your age and you said "I am my age years old". Commented May 21, 2024 at 4:14

1 Answer 1

1

Assuming that there is a file named '1.txt' in MyDocuments this should work.

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    Dim pth As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
    pth = IO.Path.Combine(pth, "1.txt")
    RichTextBox1.LoadFile(pth, RichTextBoxStreamType.PlainText)
End Sub
Sign up to request clarification or add additional context in comments.

2 Comments

Note that My.Computer.FileSystem.SpecialDirectories.MyDocuments, which the OP is trying to use but is doing so incorrectly, will produce the same path as Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments).
Noted. Thanks. I prefer the Environment.SpecialFolder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.