tl;dr version: Use GetImageResource. But it doesn’t always just work…
Now I wish that I could claim that I uniquely discovered this neat little trick, but while I will claim that I discovered it with no outside help, it’s obviously obvious enough that I’ve heard a few other people in the channel talk about it since. And how to fix “the bit that doesn’t work” (teaser – see below) is something that might be unique…
The files from these three folders should be included in a zip file that you load against your Add-In, and then will be published with your Add-In whenever they are needed – you don’t need to manually distribute any DLLs or anything else, and all Scripts and Stylesheets will be automatically loaded in the header of the Add-in. So far so brilliant.
This is where I realised the importance of testing across clients from the beginning. I do most of my Development and Testing using the Windows Client – because it’s quick and I’m used to it, but the Windows Client and the Web Client treat Control Add-Ins ever so slightly different.
When the “Image” resources get renamed for the Windows Client they just get prefixed with a path and a big number, when they get renamed for the Web Client they also get suffixed with “.png” – no matter what type they are (so you may end up with files “…banner.png.png”, “…logo.gif.png”, “…customJS.js.png”, etc…). The GetImageResource function does return the correct filename and in most cases this will probably be fine, i.e. if load a js file or css file it won’t care about the file extension.
So (again) what doesn’t work?
Well, I wrote this code to open a child window with an htm file I had included with my Resources. (Why? See this stackoverflow)
With a Windows Client Add-In this works fine, however with the Web Client the browser tries to open a file called “…ChildWindow.htm.png” and decides to treat it as an image rather than html.
So, how did I fix that?
What you can do is get IIS to tell the browser to treat the file differently by adding a Handler Mapping against the request path *.htm.png. I chose a “Module Mapping” using the ServerSideIncludeModule. I’m not sure if that is the best Handler Mapping, but it works. (This module is designed to deal with file types *.shtm & *.shtml which also are files that aren’t exactly htm but should be treated as if they are. On IIS7 this module is not enabled by default, you have to add it to the features of IIS).
And it all works, hurrah! The next bit to test is whether my childwindow will still nicely communicate with the parent window and then back to NAV… a basic Hello World seems to work… maybe I’ll get to blog about it some more, but I’ve just had 10 other projects land on my desk…