Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If suppose i am having some files(like .txt,.xml)and even a zip file which need to be extracted in between the program execution .How can i use these files wisely. Is making these files as Embedded Resource is a good way or is there any better way to do so?
My requirement is when i am executing the .exe file i should have access to these files.

What I have tried:

I have tried setting the files as Embedded Resource.
Please help.
Posted
Updated 3-Dec-20 7:43am

1 solution

It really depends on what you want to do with them. If your app just wants to read them in their entirety, then embedding them can make a lot of sense: I do that with revision history and ToDo files so I can display them in "About" boxes.

If you want to change them, then that's a bad idea because you can't - embedded resources are part of your EXE file so you cannot edit them once your app has been compiled.

If you embed your files and add them to the RESOURCES.RESX file, you can access them directly using Property.Resources.

Have a look here: One more time about Resource vs. EmbeddedResource – Ivan Krivyakov[^]
 
Share this answer
 
Comments
Member 14978771 3-Dec-20 14:06pm    
Thank you soo much for the reply. Will look into it.
Member 14978771 3-Dec-20 14:45pm    
If i added a zip file as a resource
how can i extract them to a local folder?
Tried:
ZipFile.ExtractToDirectory(Resource.zipFile, targetPath);
But not working.
OriginalGriff 3-Dec-20 15:00pm    
Try this:
https://www.codeproject.com/Articles/20257/Using-Resource-File-for-Adding-and-Extracting-ZIP
Member 14978771 4-Dec-20 12:35pm    
i added a xml file as a resource
i can read the value of an element from that file
but i am not able to update that file.Is there any way todo that?

My xml file is: Resources.BookXML

<book><mybook><price>100</price></mybook></book>


For saving i tried:
XDocument xml = XDocument.Parse(Resources.BookXML, LoadOptions.PreserveWhitespace);
xml.Root.Element("myBook").Element("Price").Value = "200";
xml.save(Resources.BookXML);

But didn't work :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900