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);



Did you check that file exists ???


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.


"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);


When you write this:


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


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


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.