Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Get Started with Silverlight Using Visual Studio 2008 and Expression Blend 2 : Page 7

The Microsoft Silverlight browser plug-in enables developers to host Rich Internet Applications (RIAs), which feature animation, vector graphics, and video playback. Find out how to get started with Silverlight, and get a feel for how this new type of development works.

Deploying Silverlight Applications
After your Silverlight application is completed, deploying it is very easy. For a production environment, there is no need to expose the source of your managed code; simply copy the compiled assembly to your web server. For example, you can copy the assembly you just created to see how easy the process is.

First, create a folder in your hard drive, say C:\MyFirstSilverlightApp.

Create an HTML page named Default.html and populate it with the following:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <!-- saved from url=(0014)about:internet --> <head> <title>Silverlight Project Test Page </title> <script type="text/javascript" src="Silverlight.js"></script> <script type="text/javascript" src="Default.html.js"></script> <style type="text/css"> .silverlightHost { width: 640px; height: 480px; } </style> </head> <body> <div id="SilverlightControlHost" class="silverlightHost" > <script type="text/javascript"> createSilverlight(); </script> </div> </body> </html>

As you observe, you can simply copy the content from the TestPage.html (from the Visual Studio 2008 project) and paste it into Default.html. The important elements are highlighted in bold.

This HTML file references two JavaScript files: Silverlight.js and Default.html.js. Like before, you can also copy them directly from the files in Visual Studio 2008 project (after copying, simply rename TestPage.html.js to Default.html.js).

By default, the Default.html.js file uses Page.xaml as the UI for your Silverlight application (see Listing 5). Hence, copy the Page.xaml from your Visual Studio 2008 project into the C:\MyFirstSilverlightApp folder.

If you look into the content of Page.xaml, you will see that the Silverlight application is expecting to find the compiled assembly in the ClientBin folder. The name of the compiled DLL is OurFirstSilverlightProject.dll:

<Canvas xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="parentCanvas" Loaded="Page_Loaded" x:Class="OurFirstSilverlightProject.Page; assembly=ClientBin/OurFirstSilverlightProject.dll" Width="640" Height="480" Background="White" >l ...

Hence, in C:\MyFirstSilverlightApp, create a new folder named ClientBin and copy the compiled DLL from the ClientBin folder of your Visual Studio 2008 project's folder.

Figure 17 shows the content of the C:\MyFirstSilverlightApp folder. As you can see, you do not need to deploy the source code of your VB program, just the assembly.

Figure 17. Content: What's inside the C:\MyFirstSilverlightApp folder.

You can now configure the C:\MyFirstSilverlightApp folder as a virtual directory in IIS. Launch IIS (you can use the inetmgr command), right-click on the Default Web Site link and select New | Virtual Directory…. Give it the alias of Silverlight and specify C:\MyFirstSilverlightApp as the location of the folder. That's it!

You can now load the page using this URL: http://localhost/Silverlight/default.html.

You've seen how to create a Silverlight application using Visual studio 2008. You define Silverlight application UIs using XAML, which you can produce with Visual Studio 2008, Expression Blend 2, or manually. Hopefully, you've been inspired to explore Silverlight more deeply.

Wei-Meng Lee is a Microsoft MVP and founder of Developer Learning Solutions, a technology company specializing in hands-on training on the latest Microsoft technologies. He is an established developer and trainer specializing in .NET and wireless technologies. Wei-Meng speaks regularly at international conferences and has authored and coauthored numerous books on .NET, XML, and wireless technologies. He writes extensively on topics ranging from .NET to Mac OS X. He is also the author of the .NET Compact Framework Pocket Guide, ASP.NET 2.0: A Developer's Notebook (both from O'Reilly Media, Inc.), and Programming Sudoku (Apress). Here is Wei-Meng's blog.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.