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

Hi!

Did you check that file exists ???

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.

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"

Hi,

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

Thanks

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.

Thank you very much, that was exactly what I wanted.

Be a part of the DaniWeb community

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