Answer the question
In order to leave comments, you need to log in
How to open a file from a VS project using C#?
There is a small piece of software. It has a button. By clicking on the button, the 1.txt file should open, which will initially already be in the project resources. That is, the file should not be opened from a specific location on the disk, but already inside the program, from its resources.
Answer the question
In order to leave comments, you need to log in
If I understand the question correctly, then something like this.
1 - Add the following using
2 - Set the following property on the desired file:
Parameter Build Action
, value Embedded Resource
3 - Use the following code
var assembly = Assembly.GetExecutingAssembly();
var resourceName = "MyCompany.MyProduct.MyFile.txt";
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
using (StreamReader reader = new StreamReader(stream))
{
string result = reader.ReadToEnd();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question