UPDATE (5/11/2010)
I am changing my domain for my new Silverlight blog to be:
http://www.michaelsnow.com
I will be retiring the name silverlightdev.net so expect this link to go dead after some time.
Sorry for an inconvenience.
--Mike
After a long hiatus from Silverlight (due to my team being moved off Silverlight ☹) I am back to blogging for Silverlight!
When it comes down to technologies, Silverlight is my greatest passion. I spend a lot of my spare time experimenting with building a wide variety of applications using Silverlight.
Going forward, I will be showcasing these applications as well as regular tips and tutorials on my new blog which can be found at:
http://www.silverlightdev.net
Using my own site I will be able to include live demos and sample source code with each tip of the day. I will be cleaning up and migrating a number of tips from here that I find still to be applicable and useful for Silverlight 4 and beyond.
Thanks,
--Mike
With Silverlight you can run your Out-of-Browser applications in elevated trust mode. This will allow you to relax the normal sandboxed barrier Silverlight restricts applications to. While you still will not have full control of the local machine, the following features are made available to you in elevated trust mode:
- Clipboard Access – Retrieve items from the system clipboard without the prompt for permissions to access the clipboard as seen below:
- HTML Hosting – Display HTML Content in the WebBrowser control.
- Removal of Cross Domain Restrictions – Your application can interact with any domain bypassing the normal security check that required the ClientAccessPolicy.xml or CrossDomain.xml files.
- File Access – Your application can now directly access files without user initiated interaction that then invokes the OpenFileDialog or SaveFileDialog dialogs. However, you are still limited to user folders such as My Documents, My Videos, My Music, My Pictures and any sub folder. Example code you can execute:
if (App.Current.IsRunningOutOfBrowser && Application.Current.HasElevatedPermissions)
{
string picturesPath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
string path = picturesPath + @"\test.txt";
StreamReader sr = new StreamReader(path);
string line = sr.ReadLine();
while (line != null)
{
line = sr.ReadLine();
}
sr.Close();
}
- Notification Window – Also know as a “toast” window, this is a small window that pops up in the lower right corner for a specified interval of time before disappearing.
- COM Interoperability – Direct access to COM enabled applications installed on the clients machine.
In order to configure your application to run in elevated mode open your project in Visual Studio 2010. Once open, right click on your Silverlight application in the solution explorer and select Properties. Under the Silverlight tab, check “Enable running application out of the browser” and click the “Out-of-Browser settings" button as circled below in the screenshot.
Once this dialog is open check the “Require elevated trust when running outside the browser” checkbox as seen circle in the screenshot below.
Now, when a user chooses to install your Silverlight application out of browser they will get this rather intimidating security warning dialog before they can proceed. Note that you can replace this dialog with something more friendly if your XAP is digitally signed (this will be covered in the next tip of the day).
Final Notes
On a final note, you will want to make certain your application verifies it’s running in out of browser mode before making calls that are required to be in this mode before being executed. Your application can check to see if it’s running in Out-of-Browser mode through this call:
if (App.Current.IsRunningOutOfBrowser)
{
}
Also, your application can verify it has elevated permissions with this call:
if (Application.Current.HasElevatedPermissions)
{
}
Thank you,
--Mike
This morning we released Silverlight 4 Tools for Visual Studio 2010!
The link to download and installs the tools is http://go.microsoft.com/fwlink/?LinkId=177508.
The tools will install:
- Silverlight 4 RTM Developer Runtime
- Silverlight 4 Tools RC for VS 2010
- Silverlight 4 SDK RTM
- Silverlight 4 Tools RC Package
- WCF RIA Services RC
Note that this is the RC release of the Silverlight 4 tools. With these tools you can start developing Silverlight 4 applications using Visual Studio 2010.
If you are not familiar with what’s new in SL 4 check out Tim’s blog here: http://timheuer.com/blog/archive/2009/11/18/whats-new-in-silverlight-4-complete-guide-new-features.aspx
If you haven’t already downloaded VS 2010, you can get the free Express version from here: http://www.microsoft.com/web/gallery/install.aspx?appid=VWD2010.
If you are a MSDN subscriber you can get the full version here: http://www.microsoft.com/visualstudio/en-us/download
Thanks and enjoy!
--Mike