I'm trying to open a text file in a program I've created but it won't work unless I specify it as an absolute file path. I can't seem to make a relative path name.

Recommended Answers

All 3 Replies

You've used .\ right?
Try System.Windows.Forms.Application.StartupPath

Member Avatar

If you have added the text file to a project and you can see it in the solution explorer then you need to click on the text file and set the build action to content and copyToOutput = copyifnewer or copyalways. You can then open it with


If it was in a folder then "TextFolder\TextFile1.txt"

here is my code that I'm currently using

If My.Computer.FileSystem.FileExists("equiplist.txt") = True Then
objReader = My.Computer.FileSystem.OpenTextFileReader("equiplist.txt")
commented: Your code looks fine to me. What's the problem. -2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.