locked
iterate WinRT Embedded Resources?

    Question

  • Hi,

    How can I iterate through the embedded resources?  I have several LibreOffice Spreadsheets I want to extract the contents of.  In .NET I was doing this:

    string resourceName = this.assemblyTurahOdsDocuments.GetName().Name + CommonNames.PropertiesResources;
    ResourceManager rm = new ResourceManager(resourceName, this.assemblyTurahOdsDocuments);
    ResourceSet resourceSet = rm.GetResourceSet(Thread.CurrentThread.CurrentUICulture, true, true);
    
    foreach (DictionaryEntry resource in resourceSet)
    {
    	string r = resource.Key.ToString();
    	string v = stringNameBuilder.GetListViewName(r, CommonNames.TurahBook);
    	string m = stringNameBuilder.GetModuleName(r, CommonNames.TurahBook);
    	string d = this.CheckSetupDataDirectory(this.propertiesService.RoamingAndLocalConfig.FilePath, CommonNames.DataDirectory, r);
    	this.TurahSummaryItems.Add(new TurahOdsDocumentItem(m, v, r, d));
    }
    rm.ReleaseAllResources();

    and would like to do much the same.  Can anyone link me to an example or share some coding to do this?

    I know how to do this and that's about it, but I want to avoid creating a list, because more files will be added later:

    this.assemblyOdsDocumentsService = typeof(OdsDocumentsService).GetTypeInfo().Assembly;
    System.IO.Stream xmlStream = this.assemblyOdsDocumentsService.GetManifestResourceStream("NathsarTS.ODSDocuments.Services.Data.TurahWritingAleppo.ods");

    Thanks!...


    Code is like a box of chocolates!...


    • Edited by VcDeveloper Thursday, December 4, 2014 8:16 PM
    Thursday, December 4, 2014 8:15 PM

Answers

All replies

  • Using embedded resources isn't recommended for Windows Runtime apps. In general Windows Runtime apps use Windows.ApplicationModel.Resources.ResourceLoader for string resources and loose files in the appx package for other resources.

    That said, you can use System.Resources.ResourceManager in the .Net Framework for Windows Store apps for string resources, but GetResourceSet is not available.

    If you really want to go with resources you'll probably have to parse them yourself.

    --Rob

    Thursday, December 4, 2014 8:39 PM
    Owner
  • Hi,

    Thanks for your reply!  Can you link me to doc's for "loose files in the appx package for other resources"?  Would appreciate it.  This looks like what I want to do.  I know how to load strings, but would like to read about the loose file loading.

    Thanks!...


    Code is like a box of chocolates!...


    • Edited by VcDeveloper Thursday, December 4, 2014 11:49 PM
    Thursday, December 4, 2014 11:47 PM
  • Hi Rob,

    Can you link me to documentation for creating and reading a app package?  I was doing this in .NET and would like to do something similar in WinRT.

    string resourceName = this.assemblyTurahOdsDocuments.GetName().Name + CommonNames.PropertiesResources;
    ResourceManager rm = new ResourceManager(resourceName, this.assemblyTurahOdsDocuments);
    ResourceSet resourceSet = rm.GetResourceSet(Thread.CurrentThread.CurrentUICulture, true, true);
    
    foreach (DictionaryEntry resource in resourceSet)
    {
    	string r = resource.Key.ToString();
    	string v = stringNameBuilder.GetListViewName(r, CommonNames.TurahBook);
    	string m = stringNameBuilder.GetModuleName(r, CommonNames.TurahBook);
    	string d = this.CheckSetupDataDirectory(this.propertiesService.RoamingAndLocalConfig.FilePath, CommonNames.DataDirectory, r);
    	this.TurahSummaryItems.Add(new TurahOdsDocumentItem(m, v, r, d));
    }
    rm.ReleaseAllResources();

    Here in this example I have LibreOffice Spreedsheets as a Resource in the .exe, but I heard its not recommended for this platform and need to create a app package.  So I'm hoping you can link me to the Doc's and examples?

    Thanks!...


    Code is like a box of chocolates!...


    Tuesday, December 9, 2014 5:01 PM
  • I found the solution here at stackOverflow "List all embedded resources in a folder".

    Code is like a box of chocolates!...

    • Marked as answer by VcDeveloper Wednesday, December 10, 2014 12:01 AM
    Tuesday, December 9, 2014 10:07 PM
  • Please don't spam the forum with the same question on multiple threads.

    Windows Store apps are all created and deployed via an appx package. To include files in your package add them to the project in Visual Studio and mark the files as content.

    Wednesday, December 10, 2014 1:53 AM
    Owner
  • Please don't spam the forum with the same question on multiple threads.

    Windows Store apps are all created and deployed via an appx package. To include files in your package add them to the project in Visual Studio and mark the files as content.

    Sir, I don't spam forum's, been here a long time and there is no history of me doing such a thing!  I don't why it shows twice in this thread and the only other post with this same problem was in a thread created by another user in which I was asking for a solution.

    When I found the solution it was best to let both threads know iI was solved.  Understand?

    So don't ever accuse me of doing this again!


    Code is like a box of chocolates!...



    • Edited by VcDeveloper Wednesday, December 10, 2014 6:03 AM
    Wednesday, December 10, 2014 6:01 AM
  • Please post your question in only one thread. Please do not post the same question in multiple threads, even if they are on related topics.

    You posted this in three separate threads. I merged the others to prevent duplication and since your question (and in particular your answer) wasn't quite the same as the other threads you posted on.

    Wednesday, December 10, 2014 11:53 PM
    Owner