Contoso Construction - LightSwitch Advanced Development Sample

Contoso Construction - LightSwitch Advanced Development Sample

Rate This
  • Comments 13

UPDATE: If you are looking for the Visual Studio 2012 version see: Contoso Construction - LightSwitch Advanced Sample (Visual Studio 2012)

Last week I demonstrated a more advanced sample at TechEd and showed different levels of customization that you can do to your LightSwitch applications as a professional developer by putting your own code into the client and server tiers. You can watch the session where I went through it here: Extending Microsoft Visual Studio LightSwitch Applications (also check out additional resources from my trip report I posted yesterday).

Download SampleDownload the Contoso Construction Sample

This sample demonstrates some of the more advanced code, screen, and data customizations you can do with Visual Studio LightSwitch Beta 2 as a professional developer (you get paid to write code). If you are not a professional developer or do not have any experience with LightSwitch, please see the Getting Started section of the LightSwitch Developer Center for step-by-step walkthroughs and How-to videos. Also please make sure you read the setup instructions below.

Features of this sample include:

  • A “Home screen” with static images and text similar to the Course Manager sample
  • Personalization with My Appointments displayed on log in
  • “Show Map..” links under the addresses in data grids
  • Picture editors
  • Reporting via COM interop to Word
  • Import data from Excel using the Excel Importer Extension
  • Composite LINQ queries to retrieve/aggregate data
  • Custom report filter using the Advanced Filter Control
  • Emailing appointments via SMTP using iCal format in response to events on the save pipeline


Building the Sample

You will need Visual Studio LightSwitch Beta 2 installed to run this sample. Before building the sample you will need to set up a few things so that all the pieces work. Once you complete the following steps, press F5 to run the application in debug mode.

1. Install Extensions

You will need the following extensions installed to load this application:
And the Bing Map control from the Training Kit:

These are .VSIX packages and are also located in the root folder of this sample. Close Visual Studio and then double-click them to install.

2. Set Up Bing Map Control

In order to use the Bing Maps Control and the Bing Maps Web Services, you need a Bing Maps Key. Getting the key is a free and straightforward process you can complete by following these steps:

  • Go to the Bing Maps Account Center at
  • Click Sign In, to sign in using your Windows Live ID credentials.
  • If you haven’t got an account, you will be prompted to create one. 
  • Enter the requested information and then click Save.
  • Click the "Create or View Keys" link on the left navigation bar. 
  • Fill in the requested information and click "Create Key" to generate a Bing Maps Key.
  • In the ContosoConstruction application open the MapScreen screen. 
  • Select the Bing Map control and enter the key in the Properties window.

3. Set Up Email Server Settings

When you create, update or cancel an appointment in the system between a customer and an employee emails can be sent. In order for the emailing of appointments to work you must add the correct settings for your SMTP server in the ServerGenerated project's Web.config:

  • Open the ContosoConstruction project and in the solution explorer select "File View".
  • Expand the ServerGenerated project and open the Web.config file.
  • You will see the following settings that you must change to valid values:

    <add key="SMTPServer" value="" />
    <add key="SMTPPort" value="25" />
    <add key="SMTPUserId" value="admin" />
    <add key="SMTPPassword" value="password" />

  • Run the application and open the employees screen, select Test User and specify a
    valid email address. When you select this user on appointments, emails will be sent here.

Additional Setup Notes:


The system is set to Forms Authentication but if you change it to Windows Authenticaion then in order for the "My Appointments" feature to work you will need to add yourself into the Employees table and specify your domain name as the user name. Make sure to specify a valid email address if you want to email appointments.

Excel Import:

In order to import data on the Materials Catalog screen, copy the StructuralMaterials.xls located in the root of this sample to your My Documents folder first. Then click the Import from Excel button on the screen and select the spreadsheet. You can them map the columns in the spreadsheet to the entity properties and the data from the spreadsheet will appear as new rows on the Materials Catalog. Click Save to send the data to the database.

Additional Resources

You can get a good understanding of more advanced LightSwitch features by working through the LightSwitch Training Kit. If you look under the “LightSwitch Advanced features” section on the right-hand sidebar on the opening page of the kit you will see the demos and labs.

Here are some more resources of Visual Studio LightSwitch to explore:

For questions related to this sample please contact me here. For other LightSwitch questions and troubleshooting please visit the LightSwitch Forums.


Leave a Comment
  • Please add 7 and 6 and type the answer here:
  • Post
  • Thanks for another great sample!

    Just one note about Filter Control - it's a fantastic control and I hope the handling of the exception I mentioned here:

    will be fixed soon.

  • Excellent video, Beth.  Videos like this showing useful examples are terrific--good info, nice presentation.  Keep up the great work.  

  • Like many people, i have this message when your Contoso application start :

    "...The database '2F2EAC41F87EB280337C4343CFF80203_L STUDIO 2010\PROJECTS\CONTOSOCONSTRUCTION\CONTOSOCONSTRUCTION\BIN\DATA\APPLICATIONDATABASE.MDF' cannot be opened because it is version 661. This server supports version 612 and earlier. A downgrade path is not supported.

    Cannot open user default database. Login failed.

    Login failed for user 'HAL\StealthWise'."

    I have read your blog "Attaching a Local SQL Server Database Using sqlcmd". But, that don't work.

    I have also change the database tools option from sqlexpress to HAL\SQLSERVERR2.

    Can you help me ?

  • Hi Beth, thanks for the article.

    I do have a question about Lightswitch and maybe it's the same for Silverlight.  How come I need to do so many refreshes after I've modified data on a screen.  For example if you add a detail item and go back to the master item the detail don't show unless you do a refresh.



  • Hi Christian,

    When you install LightSwitch Beta 2 it will install SQL Express edition. You will need that to run the sample. It sounds like you don't have it installed.

  • Do we have chart controls added for this application to show data?

  • Make the images in this post clickable. They are unreadable in Firefox or IE9.

  • This is great. Is there a way to send Task requests to Outlook using a similar function to the way you're sending the appointment requests?

  • Hi, Beth! Nice post!

    Is it possible to uso Geo Tags with bing control?

    Best regards,


  • Have you used the xCode logo from Mac in this? The icon for "Search Projects"

  • What if your SMTP requires SSL, which is most....  Where can we enable SSL in the code?  I cant get it to work because the SMTP's I use require SSL and I get an error

  • @JoeJ - You should be able to just set the smtpclient.EnableSSL = True in the mail helper class. See

  • Thanks, that did it.

    I have something im going to try later when I'm home, but worth asking anyways. Do you think its possible instead of using an address, that using a Lat and Long can be used for map location? I deal with sites in which some are off road, so it'd be helpful to use coordinates.

Page 1 of 1 (13 items)