0

Hello,

I have a textfile added to a resx file. The resx file is called Resources.

I have a filestream, and I want to create a filestream object with the textfile.

I swear it was working, but now it throws me an argument not valid exception here is my code

FileStream fsTextFile = new FileStream(Resources.TextFile, FileMode.Open, FileAccess.Read);

Thanks

2
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by MrCapuchino
0

Hi,

Yes the file exists, it is in the resources folder as well as added in the resources.resx file.

Am I doing it right? I mean it works if I specify the path but it does not work if I try to use the resources file.

0

Hi!

"FileStream" requires path of a file, so you should try like this:

FileStream fsTextFile = new FileStream(Application.StartupPath.Replace("\\bin\\Debug","\\Resources\\TextFile.txt"), FileMode.Open, FileAccess.Read);

*EDIT****

When you write this:

Resources.TextFile

it refers to the contents of the file which may or may not be a "File Path"

Edited by ShahanDev: n/a

0

Hi,

Ok that works, when I compile my program it will work too even If I move the compilation to another computer?

Thanks

0

Yes, it will work. Since your file is in "Resources" folder and "resources" folder belongs to the same "project" folder. So, wherever your project will be move it will work accordingly.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.