Reading a file in c# using VS2005

Im currently reading a file off of my desktop and processing the contents. I want to attach this file to the project so that wherever this program is used it will still work.
I tried, project -> add component which adds the text file. However when using Streamreader etc what is the address that you put in? I tried just the name of the file e.g.

StreamReader t = new StreamReader("textfile.txt");

but this didn't work.

Cheers guys.
Who is Participating?
abelConnect With a Mentor Commented:
If you added a text file, then while you debug, you must make sure that the text file is also copied to the destination directory as part of the project. By default, it is not. See screenshot: the "Copy to Output Dir" must be set to "Copy Always". Then you can use the relative directory as you do above.

You have to put in the absolute path.

So if your going to use a file from your desktop then you'll go to

C:\Documents and Settings\USER\Desktop\file.txt

Hope this helps
mike_proAuthor Commented:
Awesome, thanks for the help!
> Awesome, thanks for the help!
you're welcome. Long time ago it took me ages to find out why things weren't copied... Glad to be of help ;-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.