Search code examples
c#resourcesresx

OPEN a Resource.resx file instead of Creating it which overrides the previous Resource.resx file


I start my application from withint Visual Studio 2010. I add then some files into my application and each file type`s icon like icon from doc,docx,xls,pdf etc are added as String/Bitmap key/value pair to my IconImages.Resx file via

private void DumpTempResourceToRealResourceFile(IDictionary<String, Bitmap> tempResource)
        {

            using (ResXResourceWriter writer = new ResXResourceWriter("IconImages.Resx"))
            {
                foreach (KeyValuePair<String,Bitmap> item in tempResource)
                {
                    writer.AddResource(item.Key, item.Value);                    
                }
                writer.Generate();
            }            
        }

When the icons are added to the resource I close the application.

Then I start my application again with VS 2010 and add some files within my document application. The file types are written again to my IconImages.Resx. Then I close my application and check the IconImages.Resx file under the \bin\ folder and the previous saved images are gone and I have new/different ones now.

Why can I not say OPEN a .resx file and append stuff to it? Everytime I create a ResourceWriter object with the same name "IconImages.Resx" I overwrite the previous added stuff and thats stupid.

How can my IconImages.Resx file stay alive over an application session without being overwritten by other stuff I add?


Solution

  • I am having now a lookup table "FiletypeImage" with the filetype ".docx" and the raw binary data aka blob. This table gets retrieved in my documentService and cached in a static variable. with a Get and Add method which are called by my DocumentListViewModel. Its very fast thx to sqlite :)