Read "Embedded Resource"

I’m searching for a way to read an embedded resource within NETMF. Let’s say I add a textfile myfile.txt to my project and set the Build Action to “Embedded Resource”.
In full .NET framework one would get a stream to the textfile like this:

Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("myfile.txt")

However, the method GetManifestResourceStream doesn’t seem to exist in NETMF. Is there a workaround for this?


@ WouterH - I know this is going to be a silly question as I know you are an experienced FEZer, but why not just add the file as a resource?

Is there some specific use case you have in mind?

@ taylorza: well I wanted to add a website with multiple files in a folder structure. F.e wanted to add ‘index.html’ file to my project and set the Build Action to “Embedded Resource”, but there seems no way to read the contents of that embedded file in NETMF.

I now added a “index” textfile as a normal resource and I can read it like a string:

string content = Resources.GetString(Resources.StringResources.index);

Things I’m missing with this method:

  1. I don’t have syntax highlighting for javascript, css and html files, because they all will have the .txt extension.
  2. I’m not able to create a folder-like structure of the web files.
  3. I can’t easily preview the website on my development machine because of the .txt extension

@ WouterH - I can only answer to point 1 and 3. If you add the .HTM file with the .HTM extension you can then edit the files in the Resources folder with full syntax highlighting. While the default extension is .txt, there is no problem (that I have come across) having another extension.

I quickly looked through the code from the porting kit and it does not look like there is support for reading resources from the manifest. It does not look like it is going to be possible to read embedded resources.

You could use creative naming to handles this.


The structure above can be represented in the names for the resources.


Real pity is that the resources cannot be loaded by name, so you will need to maintain a mapping for names to id’s, when the request comes in you construct the name based on the requested file and then look it up to get the correct resource id to load.

Thank you taylorza, I was not aware that I could add a .html and .js file and still read is as a StringResource. I can live with having no folder structure.