0

In my project I created a Text file and placed it inside the folder Resources. Is there any way to access that file?

I have a WPF control that access this file and I can't get it to work.

I've already tried to go by project path StreamReader myFile = new StreamReader("C:\ProjectFolder\ProjectName\Resources\file.txt") and this solution there's a conflict.

The first solution let's me, in code mode work normally, but at runtime the app crashes because it can't find the path. Says the path to (Project)\bin\debug\file.txt does not exist. On the other hand the second solution let's me run/degug the app perfectly but when I try to edit the xaml Design of the control that hosts the code, it tells me that cannot find full path to file.

Can anyone help? Thanks a lot

1 Answer 1

1

Try this:

Stream myFile = new StreamReader(@"C:\ProjectFolder\ProjectName\Resources\file.txt");

The slashes are interpreted by the compiler as escape sequences, and using the '@' intructs the compiler to take the string literally without honouring the escape sequences.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot. It actually works :DDD. But I have a question: When the app is finished and I create the setup so it can be installed on different machines, will this still work???
@David, I don't think so, but I don't have the solution. Seemingly the path would have to be provided in the app configuration or be made relative.

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.