How to add file in Resource file in C# ?
Steps, how to use it.
Steps
1. Right click on project and select properties
2. Click on Resources option from left side
3. Click on link available in middle of the section, link as "This project does not contain a default resource file. Click here to create one."
4. Click on "Add Resource" from section menu and select "Add Existing File"
5. Select file from your file path
6. File is added in resource file
7. You can rename file name as per your requirement
Code
How to use file content in C# program
Add namespace
using projectNameSpace.Properties;
Now you can do process on fileContent as per your requirement.
Add namespace
using projectNameSpace.Properties;
byte[] file = Resources.FileName;
Stream stream = new MemoryStream(file);
string fileContent = "";
using (StreamReader reader = new StreamReader(stream))
{
fileContent = reader.ReadToEnd();
}
Now you can do process on fileContent as per your requirement.
Hope this will help you and save your time.
Enjoy !!!
:)
No comments:
Post a Comment