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.
mike_proAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

abelCommented:
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.

ScreenShot300.png
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NicoJuicyCommented:
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
0
mike_proAuthor Commented:
Awesome, thanks for the help!
0
abelCommented:
> 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 ;-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.