I created a file in the solution of my project. How do I read this file? It should stay in solution because when compiling it should be wrapped in .exe.
I created a file in the solution of my project. How do I read this file? It should stay in solution because when compiling it should be wrapped in .exe.
First you need to configure the file to be copied to bin
in build of your solution :
If it is a text file, you can read this file with the following command:
var reader = new StreamReader(@"meuarquivo.txt");
For files within the executable, the translation of this article is essentially: link . I'll explain succinctly.
using System.IO;
using System.Reflection;
try
{
var assembly = Assembly.GetExecutingAssembly();
var imageStream = assembly.GetManifestResourceStream("MeuArquivo.txt");
}
catch
{
throw new Exception("Erro acessando arquivo de resource.");
}