using (SteamReader sr = new StreamReader(\"text.txt\"))
I also tried to don\'t put the text file on the .resx
file.
The StreamReader
constructor that you are using expects the file to exist on the disk. If the file is embedded inside your assembly you could use the GetManifestResourceStream method.
For example:
// Get the current assembly. If the file is embedded inside a different
// assembly you will need to get that assembly
var assembly = Assembly.GetExecutingAssembly();
using (var stream = assembly.GetManifestResourceStream("AssemblyName.test.txt"))
using (var sr = new StreamReader(stream))
{
...
}
The key under which the resource is embedded into your assembly will depend on where is the file situated in the hierarchy. It is always prefixed with the assembly name and then any possible subfolders if you have some.
Make sure that the Build Action
is set to Embedded Resource
for this file in its properties. And here's an article with more details about accessing embedded resources.