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" 
<html xmlns="http://www.w3.org/1999/xhtml" >
<!-- saved from url=(0014)about:internet -->
    <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; }

    <div id="SilverlightControlHost" class="silverlightHost" >
        <script type="text/javascript">
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:

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.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date