I guess that it’s time to write about it, after making a few people curious at the MVP summit in Seattle. This article is to be taken as a proof of concept, and (I hope) as a way to “motivate” Microsoft to integrate this ability into Silverlight.
As soon as I started playing with Silverlight, I saw the great potential that this technology has. As a RIA technology, it provides extended functionality over the web. As a WPF subset, it allows me to leverage the knowledge I already acquired in the past, and to reuse it for web applications. This in itself makes Silverlight a technology I *have to* learn.
But what if… what if we could use Silverlight to run lightweight .NET applications in standalone mode? A little like Adobe AIR is offering, but with the power of .NET instead of ActionScript. Imagine a small application, running on a small framework, installed in typically 10 seconds.
I posted an article on my site explaining the thought process and giving information about standalone Silverlight applications, their promises and their limitations. For those of you too impatient to read the full article :) you can download a demo and the source code directly from here.
To install the demo, follow the steps:
- Download the Zip file.
- Extract the Zip file to a folder on your hard drive.
- On Windows: double-click the file “Start.hta”.
This starts the MSHTA host, and displays the Silverlight application.
- Enter a directory path in the first textbox, and then click on “Get list of files”. This displays the corresponding list in the listbox.
- Select a file. Its name is displayed in the second textbox.
- You can now modify the file name and press on “Rename”.
- Enter any file path in the last textbox and press “Does file exist?”. A corresponding message is displayed in the status bar.
This last functionality is also available in Mozilla-based browsers, for example Firefox. You can try it by setting Firefox to be your default browser, and then double-clicking the file “index.html” located in the same folder as “index.hta”. This starts the application in “file” mode, and you get the same permissions. The other functionalities “Get list of files” and “Rename” are not implemented in Firefox and will raise an error.
As usual, the source code is available for download. It contains the following projects:
- GalaSoft.SL.IO: This is a library defining a new DirectoryInfo and FileInfo classes. These classes mimic the actual System.IO.DirectoryInfo and System.IO.FileInfo classes. They use the class “GalaSoft.SL.IO.ScriptFacade” to channel the full-trust calls to the script code contained in the file “script\gslb.filesystemexplorer.js”.
Note: The console application “GalaSoft.SL.IO.Test.Prepare” must be executed before the unit test is run.
In normal use, the project GalaSoft.SL.TestHta should be chosen as startup project, and its file “index.html” as startup page. You can modify the application code. If you change the HTML code, the changes will automatically be copied to “index.hta” when you build the application.