Share via


Problem updating embedded resource files

Question

Monday, August 18, 2008 3:45 PM

Hello,
 
I have an application which copies certain embedded resources into a specific user directory.  It works fine.
However, I want to be able to update the embedded resources.  If I copy over or edit the embedded resource files it continues to output the outdated files.
However, if I edit it by double clicking on the resource in the solution explorer and save it there, then it DOES update.
Why doesn't it update when I overwrite the file outside of solution explorer?

All replies (3)

Monday, August 18, 2008 4:04 PM ✅Answered

Embedded resources are compiled in....by copying them and not doing a build, they won't get propagated.


William Wegerson (www.OmegaCoder.Com)


Thursday, August 21, 2008 5:59 AM ✅Answered

Hi S.R.H_

I agree with Omega, embedded resources are copied to assembly instead of build, to update it, you can remove/add the resource file in solution explorer, and them rebuild it to implement this.

For the embedded XML file lost some content, I believe that problem was caused by the following code.

File.WriteAllText(WritePath + "MyEncryptedXML.xml", reader.ReadToEnd()); 

Because the encrypted file is a binary file rather than text file, therefore, use the following code snippet will be appropriate, which process the file as binary file.

  StreamReader reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("ParameterUpdater.Resources.MyEncryptedXML.xml"));

            byte []buffer = new byte[reader.BaseStream.Length];

            reader.BaseStream.Read(buffer, 0, buffer.Length);

            File.WriteAllBytes(WritePath + "MyEncryptedXML.xml", buffer);

 

And here is a solved thread about how to read embedded resource in c#.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3398832&SiteID=1

Regards,

Xun


Please remember to mark the replies as answers if they help and unmark them if they provide no help.


Monday, August 18, 2008 5:15 PM

Strangely that is not what I observed.

Building the project did not make a difference... it still was looking at the outdated files when I copied it into my resources directory.  However, if I modified one of the resource files from the Solution Explorer and saved it and ran the project it would use the updated file whether or not I rebuilt.

Also, I have found that the application is not quite working properly: some of the resource files are encrypted xmls, and when writing them it is changing the data.

StreamReader reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("ParameterUpdater.Resources.MyEncryptedXML.xml"));  
File.WriteAllText(WritePath + "MyEncryptedXML.xml", reader.ReadToEnd()); 

The embedded .xml file is 4.78KB, but the output is 2.73KB.  How is data being lost when I am writing it straight from the stream?