<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Heavily Caffeinated</title><link>http://blogs.msdn.com/b/rmattsampson/</link><description>Good stuff about life at Microsoft and being a Software Tester on Visual Studio LightSwitch</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>ASP.NET SignalR and LightSwitch (VS 2012 Update 2)!!!</title><link>http://blogs.msdn.com/b/rmattsampson/archive/2013/03/14/asp-net-signalr-in-lightswitch.aspx</link><pubDate>Thu, 14 Mar 2013 19:13:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10402414</guid><dc:creator>Matt Sampson</dc:creator><slash:comments>11</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/rmattsampson/rsscomments.aspx?WeblogPostID=10402414</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/rmattsampson/commentapi.aspx?WeblogPostID=10402414</wfw:comment><comments>http://blogs.msdn.com/b/rmattsampson/archive/2013/03/14/asp-net-signalr-in-lightswitch.aspx#comments</comments><description>&lt;p&gt;&lt;strong&gt;&lt;span style="font-size: small;"&gt;Update&lt;/span&gt; -&amp;nbsp;I uploaded&amp;nbsp;the&amp;nbsp;code and project to&amp;nbsp;MSDN Code Gallery here: &lt;a href="http://code.msdn.microsoft.com/LightSwitch-and-SignalR-4d7ff7a8"&gt;http://code.msdn.microsoft.com/LightSwitch-and-SignalR-4d7ff7a8&lt;/a&gt;&amp;nbsp;&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;SignalR? What is that?&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://github.com/SignalR/SignalR" target="_blank"&gt;SignalR&lt;/a&gt; is described as &amp;ldquo;Incredibly simple real-time web for .NET&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s a great way for a JavaScript client to call directly into Server side methods, and a great way for the Server to push up updates or notifications to the JavaScript client.&lt;/p&gt;
&lt;p&gt;I heard a couple people raving about SignalR recently, and figured it was time to see if we could get LightSwitch and SignalR to meet.&lt;/p&gt;
&lt;h2&gt;LightSwitch&amp;hellip;meet SignalR&lt;/h2&gt;
&lt;p&gt;We&amp;rsquo;re going to make a simple LightSwitch (LS) application here. And then we are going to use SignalR to push up some real-time notifications to the LightSwitch HTML Client.&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;ll end up with a LS HTML App that receives a notification every time a new entity is inserted or updated.&lt;/p&gt;
&lt;p&gt;This would allow for any user to know when ever data has been changed.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s start out with a simple &amp;ldquo;Contacts&amp;rdquo; LS app.&amp;nbsp; Everything here should be pretty basic if you&amp;rsquo;ve done any LS stuff before.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Create a new project &amp;ndash; LightSwitch HTML Application (Visual C#)&lt;/li&gt;
&lt;li&gt;Call it - &amp;ldquo;ContactsSignalR&amp;rdquo;&lt;/li&gt;
&lt;li&gt;Add a table &amp;ndash; call it &amp;ldquo;Contact&amp;rdquo;&lt;/li&gt;
&lt;li&gt;The table should look something like this when you are done:&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/5758.image_5F00_66654084.png"&gt;&lt;img style="display: inline;" title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/0574.image_5F00_thumb_5F00_2CE2308D.png" alt="image" width="558" height="367" border="0" /&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Now let&amp;rsquo;s make a simple HTML Browse Screen around the &amp;ldquo;Contacts&amp;rdquo; data&lt;/li&gt;
&lt;li&gt;In the screen designer, select &amp;ldquo;Screen | Browse Contacts (Browse Screen)&amp;rdquo; and set the property &amp;ldquo;Behavior &amp;ndash; ScreenType&amp;rdquo; to &amp;ldquo;Edit&amp;rdquo;. This will enable the &amp;ldquo;Save&amp;rdquo; button to show on our screen.&lt;/li&gt;
&lt;li&gt;Now let&amp;rsquo;s add a data item to our screen &amp;ndash; so in the Screen Designer click your &amp;ldquo;Add Data Item&amp;hellip;&amp;rdquo; button&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/2211.image_5F00_658CDA9A.png"&gt;&lt;img style="display: inline;" title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/5857.image_5F00_thumb_5F00_3A484393.png" alt="image" width="128" height="35" border="0" /&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;That&amp;rsquo;ll open up a dialog &amp;ndash; let&amp;rsquo;s call this property &amp;ldquo;updates&amp;rdquo; and make sure &amp;ldquo;Is Required&amp;rdquo; is unchecked. It should look like this:&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/7827.image_5F00_7A122A18.png"&gt;&lt;img style="display: inline;" title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/7411.image_5F00_thumb_5F00_3DE65E70.png" alt="image" width="341" height="313" border="0" /&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Now drag and drop your updates data item onto your screen &amp;ndash; put it right below the &amp;ldquo;Command Bar&amp;rdquo; so that it looks like:&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/7485.image_5F00_449967F3.png"&gt;&lt;img style="display: inline;" title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/6431.image_5F00_thumb_5F00_04634E79.png" alt="image" width="275" height="185" border="0" /&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Select the &amp;ldquo;updates&amp;rdquo; control on the screen designer and set the following properties:&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;Label Position: Hidden&lt;/li&gt;
&lt;li&gt;Font Style: Large&lt;/li&gt;
&lt;/ol&gt;
&lt;li&gt;We&amp;rsquo;ll use this control later on to post our &amp;ldquo;real-time&amp;rdquo; updates to the screen&lt;/li&gt;
&lt;li&gt;Now I&amp;rsquo;d like to be able to Add and Edit new Contacts entities here, so select the Command bar, right click and say &amp;ldquo;Add button&amp;rdquo;&lt;/li&gt;
&lt;li&gt;Select Contacts.addAndEditNew and Navigate To: New Screen like this:&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/3386.image_5F00_24122841.png"&gt;&lt;img style="display: inline;" title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/7827.image_5F00_thumb_5F00_2AC531C4.png" alt="image" width="370" height="164" border="0" /&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;This is a easy way to quickly create a new Add/Edit screen for the Contacts entity&lt;/li&gt;
&lt;li&gt;Important! - After the screen is created your Screen Designer changes to show the AddEditContact screen. Make sure you double click the &amp;ldquo;BrowseContacts&amp;rdquo; screen again to set focus back.&lt;/li&gt;
&lt;li&gt;Do the same thing again &amp;ndash; add an EditSelected button this time for the existing screen you just made, like this:&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/5758.image_5F00_1C86B8D4.png"&gt;&lt;img style="display: inline;" title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/3288.image_5F00_thumb_5F00_3C35929C.png" alt="image" width="404" height="199" border="0" /&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Basic App is done. Onto SignalR&lt;/h2&gt;
&lt;p&gt;At this point, we&amp;rsquo;ve basically made a simple LS App to add and edit new Contacts.&lt;/p&gt;
&lt;p&gt;Now we need to shove in some SignalR.&amp;nbsp; To do that we first need to &amp;ldquo;NuGet&amp;rdquo; our projects.&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;In the Solution Explorer toolbar switch to &amp;ldquo;File View&amp;rdquo; like so:&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/4377.image_5F00_22CD8F62.png"&gt;&lt;img style="display: inline;" title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/7024.image_5F00_thumb_5F00_499BA5A2.png" alt="image" width="178" height="88" border="0" /&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Now right click the HTMLClient project and select Manage NuGet Packages:&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/4375.image_5F00_5B78396F.png"&gt;&lt;img style="display: inline;" title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/8883.image_5F00_thumb_5F00_02464FB0.png" alt="image" width="223" height="30" border="0" /&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Now select Online packages, search on SignalR and install the below entry:&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/7411.image_5F00_7B271337.png"&gt;&lt;img style="display: inline;" title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/5342.image_5F00_thumb_5F00_68DE4C75.png" alt="image" width="297" height="72" border="0" /&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;This will add the SignalR JavaScript references to your HTML Client&lt;/li&gt;
&lt;li&gt;But we need to add them to the default.htm file as well, so open up that file and these two lines:&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&amp;lt;script type="text/javascript" src="Scripts/jquery.signalR-1.0.1.js"&amp;gt;&amp;lt;/script&amp;gt; &lt;br /&gt;&amp;lt; script src="../signalr/hubs"&amp;gt;&amp;lt;/script&amp;gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The first line is a reference to the SignalR library&lt;/li&gt;
&lt;li&gt;The second line is actually a reference to some JavaScript that will be dynamically generated by our SignalR server later on.&lt;/li&gt;
&lt;li&gt;Now right click the Server project, and select &amp;ldquo;Manage NuGet Pacakages&amp;hellip;&amp;rdquo;&lt;/li&gt;
&lt;li&gt;This time we want to install the SignalR package for .NET server components:&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/0167.image_5F00_367A78F6.png"&gt;&lt;img style="display: inline;" title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/4375.image_5F00_thumb_5F00_6F252303.png" alt="image" width="485" height="48" border="0" /&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;NuGet is done. Put SignalR code into the Server!&lt;/h2&gt;
&lt;p&gt;We&amp;rsquo;ll need to add some Server side code here to start up the SignalR Server Hub. And to allow for the client and the server to talk to each other.&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;Right click the Server project again and say &amp;ldquo;Add &amp;ndash;&amp;gt; New Item&amp;rdquo;&lt;/li&gt;
&lt;li&gt;Add a Global.asax file to our project &amp;ndash; we will need this to put in some custom application start up code&lt;/li&gt;
&lt;li&gt;Right click the Server project again and say &amp;ldquo;Add &amp;ndash;&amp;gt; New Item&amp;rdquo;&lt;/li&gt;
&lt;li&gt;This time add a &amp;ldquo;Web Api Controller&amp;rdquo; class to our project.&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;We only do this because it will automatically pull in some dll references for us that we&amp;rsquo;ll need later.&lt;/li&gt;
&lt;/ol&gt;
&lt;li&gt;Open up your Global.asax.cs file and paste in the follow code:&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;
&lt;pre class="csharpcode"&gt;        &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Application_Start(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)
        {
            var config = &lt;span class="kwrd"&gt;new&lt;/span&gt; Microsoft.AspNet.SignalR.HubConfiguration
            {
                EnableCrossDomain = &lt;span class="kwrd"&gt;true&lt;/span&gt;
            };
            RouteTable.Routes.MapHubs(config);

            RouteTable.Routes.MapHttpRoute(
                name: &lt;span class="str"&gt;"DefaultApi"&lt;/span&gt;, routeTemplate: &lt;span class="str"&gt;"api/{controller}/id"&lt;/span&gt;, 
                defaults: &lt;span class="kwrd"&gt;new&lt;/span&gt; { id = System.Web.Http.RouteParameter.Optional }
            );
        }&lt;/pre&gt;
&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;This code will get called when our LS app starts.&amp;nbsp; It starts up the SignalR server hub so that the clients can connect to it.&lt;/li&gt;
&lt;li&gt;Right click your Server project and add one more file &amp;ndash; a class file and call it ContactHub&lt;/li&gt;
&lt;li&gt;Past the below code into your class:&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; LightSwitchApplication
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ContactHub : Hub
    {
    }
}&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;All we are doing is creating our own Hub here that we&amp;rsquo;ll use later to talk to the client from the server.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Put SignalR into the Client!&lt;/h2&gt;
&lt;p&gt;We need to put some basic JavaScript code into our Browse screen so that it can modify the &amp;ldquo;updates&amp;rdquo; label, and so that the Server has a function to call on the Client.&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;Open up the Browse Contacts screen&lt;/li&gt;
&lt;li&gt;Select the Write Code &amp;ndash; create method:&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/1680.image_5F00_78F4BB00.png"&gt;&lt;img style="display: inline;" title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/5383.image_5F00_thumb_5F00_0AD14ECE.png" alt="image" width="123" height="87" border="0" /&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;This is where we&amp;rsquo;ll add our basic JavaScript. So copy and paste the below code into the BrowseContacts.js file&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;/// &amp;lt;reference path="../GeneratedArtifacts/viewModel.js" /&amp;gt;&lt;/span&gt;
&lt;span class="rem"&gt;/// &amp;lt;reference path="../Scripts/jquery.signalR-1.0.1.js" /&amp;gt;&lt;/span&gt;

myapp.BrowseContacts.created = &lt;span class="kwrd"&gt;function&lt;/span&gt; (screen) {
    &lt;span class="rem"&gt;// Write code here.&lt;/span&gt;
    $(&lt;span class="kwrd"&gt;function&lt;/span&gt; () {
            
        contact = $.connection.contactHub;
        contact.client.broadcastMessage = &lt;span class="kwrd"&gt;function&lt;/span&gt; (message) {
            screen.updates = message;
        };     

        $.connection.hub.start()
        .done(&lt;span class="kwrd"&gt;function&lt;/span&gt; () {
        })
        .fail(&lt;span class="kwrd"&gt;function&lt;/span&gt; () {
            alert(&lt;span class="str"&gt;"Could not Connect! - ensure EnableCrossDomain = true"&lt;/span&gt;);
        });
    });
};&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;Here&amp;rsquo;s what this does:&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;$.connection.contactHub &amp;lt;- This is our connection to the ContactHub we made on our server&lt;/li&gt;
&lt;li&gt;contact.client.broadcastMessage &amp;lt;- this is the JavaScript function we are going to invoke from the Server (which we&amp;rsquo;ll do shortly).&amp;nbsp; This function will set the &amp;ldquo;updates&amp;rdquo; screen item with some text.&lt;/li&gt;
&lt;li&gt;$.connection.hub.start() &amp;ndash; this just &amp;ldquo;starts&amp;rdquo; up the connection from the client to the SignalR Hub&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;
&lt;h2&gt;Almost done! Let&amp;rsquo;s have the Server call the Client.&lt;/h2&gt;
&lt;p&gt;We need one final piece here &amp;ndash; call into the JavaScript client every time a Contact is inserted or edited.&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;So double click the Contact&amp;rsquo;s entity.&lt;/li&gt;
&lt;li&gt;Select Write Code &amp;ndash; &amp;gt; Contacts_Inserted&lt;/li&gt;
&lt;li&gt;Paste in the below code:&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;
&lt;pre class="csharpcode"&gt;        &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Contacts_Inserted(Contact entity)
        {
            &lt;span class="kwrd"&gt;string&lt;/span&gt; message = &lt;span class="str"&gt;"A contact for "&lt;/span&gt; + entity.FirstName + &lt;span class="str"&gt;" "&lt;/span&gt; + entity.LastName + &lt;span class="str"&gt;" was just created"&lt;/span&gt;;
            var context = GlobalHost.ConnectionManager.GetHubContext&amp;lt;ContactHub&amp;gt;();
            context.Clients.All.broadcastMessage(message);      
        }&lt;/pre&gt;
&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;This will call the the &amp;ldquo;broadcastMessage&amp;rdquo; JavaScript function we wrote earlier for ALL active LightSwitch clients when a Contact is inserted. When that function is called &amp;ndash; the updates label will automatically be updated to show our message.&lt;/li&gt;
&lt;li&gt;Do this again for the Contacts_Updated method. So open up the entity again. Select Write Code &amp;ndash;&amp;gt; Contacts_Updated.&lt;/li&gt;
&lt;li&gt;Paste in the below code:&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;
&lt;pre class="csharpcode"&gt;        &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Contacts_Updated(Contact entity)
        {
            &lt;span class="kwrd"&gt;string&lt;/span&gt; message = &lt;span class="str"&gt;"A contact for "&lt;/span&gt; + entity.FirstName + &lt;span class="str"&gt;" "&lt;/span&gt; + entity.LastName + &lt;span class="str"&gt;" was just updated"&lt;/span&gt;;
            var context = GlobalHost.ConnectionManager.GetHubContext&amp;lt;ContactHub&amp;gt;();
            context.Clients.All.broadcastMessage(message);
        }&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;Same thing here as the Inserted method, except it will only be called when a Contact is updated.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;That&amp;rsquo;s it! F5 it and hang on.&lt;/h2&gt;
&lt;p&gt;F5 the LS app to build it and run it.&lt;/p&gt;
&lt;p&gt;A browser should launch.&lt;/p&gt;
&lt;p&gt;Go ahead and create a new Contact and Save it.&amp;nbsp; You should see something like this after you save.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/4382.image_5F00_4C89AAAA.png"&gt;&lt;img style="display: inline;" title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/0184.image_5F00_thumb_5F00_3E4B31BA.png" alt="image" width="457" height="104" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This is cool&amp;hellip;BUT try this with 2 browsers opened to really blow your mind.&lt;/p&gt;
&lt;p&gt;So launch another instance of your web browser.&lt;/p&gt;
&lt;p&gt;Copy and paste your &lt;a href="http://localhostNNNN"&gt;http://localhost:NNNN/HTMLClient&lt;/a&gt; URL from your first browser into the second browser&amp;rsquo;s address bar.&lt;/p&gt;
&lt;p&gt;Now create another record again. You&amp;rsquo;ll see this:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/8512.image_5F00_13069AB3.png"&gt;&lt;img style="display: inline;" title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/0753.image_5F00_thumb_5F00_6BCC517D.png" alt="image" width="603" height="81" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Both browsers got updated at the same time!&lt;/p&gt;
&lt;p&gt;That&amp;rsquo;s pretty awesome, IMO.&lt;/p&gt;
&lt;p&gt;So awesome, that I had to make a YouTube video for it:&lt;/p&gt;
&lt;div id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:b0b79492-75df-496f-a755-1138d04a6ab1" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"&gt;
&lt;div&gt;&lt;object width="425" height="355"&gt;&lt;param name="movie" value="http://www.youtube.com/v/FSEc0KeA1yE&amp;amp;hl=en" /&gt;&lt;/object&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Please feel free to leave any feedback, and I&amp;rsquo;ll post my app up on Code Gallery for others to check out (will update this once the application is available).&lt;/p&gt;
&lt;div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:e497f60d-73c5-44d1-93d1-90987fa9c32c" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/SignalR" rel="tag"&gt;SignalR&lt;/a&gt;,&lt;a href="http://technorati.com/tags/LightSwitch" rel="tag"&gt;LightSwitch&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Visual+Studio" rel="tag"&gt;Visual Studio&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;Thanks All!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10402414" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/LightSwitch/">LightSwitch</category><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/Visual+Studio+LightSwitch/">Visual Studio LightSwitch</category><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/Visual+Studio+2012/">Visual Studio 2012</category><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/SignalR/">SignalR</category></item><item><title>LightSwitch – 10 Performance Tweaks Anyone Can Do</title><link>http://blogs.msdn.com/b/rmattsampson/archive/2012/12/28/lightswitch-performance-tweaks-anyone-can-do.aspx</link><pubDate>Fri, 28 Dec 2012 19:19:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10381193</guid><dc:creator>Matt Sampson</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/rmattsampson/rsscomments.aspx?WeblogPostID=10381193</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/rmattsampson/commentapi.aspx?WeblogPostID=10381193</wfw:comment><comments>http://blogs.msdn.com/b/rmattsampson/archive/2012/12/28/lightswitch-performance-tweaks-anyone-can-do.aspx#comments</comments><description>&lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;“&lt;strong&gt;HOW&lt;/strong&gt; can I improve performance in my LightSwitch app?” – is a question that pops up in the MSDN Forums frequently enough (like &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/lightswitch/thread/f5bd49c2-3dc5-4ea9-923c-1ea797f47ff3" target="_blank"&gt;here&lt;/a&gt; and &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/lightswitch/thread/e80a64b7-2e61-4f0e-acd8-0b4b5b20f880" target="_blank"&gt;here&lt;/a&gt;).&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;I’ve got some basic tips below that show how to make some some simple tweaks to your LightSwitch app that could improve your performance:&lt;/font&gt;&lt;/p&gt;  &lt;h3&gt;1) Non active &amp;quot;tabs&amp;quot;&lt;/h3&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2"&gt;If you have non active “tabs” on your screen, you should know that they still execute HTTP queries over your network to retrieve data. .&amp;#160; One work around for this is to break out your tabs into separate screens.&lt;/font&gt;&lt;/p&gt;  &lt;/blockquote&gt;  &lt;h3&gt;2) Data columns you don’t care about&lt;/h3&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2"&gt;IF you have control over the data model, consider breaking out columns that you don't show on the screen into separate tables, and then create a 0..1 relationship with that table.&amp;#160; For example, let's say you have a Customers entity that has a picture of the current customer, but you don't show that picture on the screen.&amp;#160; That picture data is still going to be requested and thus hurt performance.&amp;#160; A way around that would be to refactor the data model and place the picture data into a separate table that is related to customers by a 0..1 relationship.&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font size="2"&gt;Reference properties on your entities are another piece of data that can slow down your performance.&amp;#160; If you have reference properties on your entity, but you don’t care about them, then consider removing them from your screen&lt;/font&gt;&lt;/p&gt;  &lt;/blockquote&gt;  &lt;h3&gt;3) Computed Properties and Validators&lt;/h3&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2"&gt;Avoid performing queries in computed properties and validators.&amp;#160; Or consider &amp;quot;persisting&amp;quot; computed properties IF it makes sense (I do just that on my blog here: &lt;/font&gt;&lt;a href="http://blogs.msdn.com/b/rmattsampson/archive/2012/03/19/odata-apps-in-lightswitch.aspx"&gt;&lt;font size="2"&gt;OData Apps In LightSwitch, Part 1&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt;)&lt;/font&gt;&lt;/p&gt;  &lt;/blockquote&gt;  &lt;h3&gt;4) Editable Grid Screens vs. List and Details&lt;/h3&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2"&gt;As a general rule, List and Details screens perform better than a Editable Grid screen.&lt;/font&gt;&lt;/p&gt;  &lt;/blockquote&gt;  &lt;h3&gt;5) A bit more advanced IIS Server tweaks&lt;/h3&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2"&gt;There are other options that you could consider on the IIS Server (assuming there is one).&amp;#160; Enabling &lt;a href="http://technet.microsoft.com/en-us/library/cc753681(v=WS.10).aspx" target="_blank"&gt;dynamic compression&lt;/a&gt; could be helpful if you have CPU cycles to spare on the IIS Server, and you suffer from limited available network bandwidth.&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font size="2"&gt;Having your data tier machine (for example the SQL Server) and your IIS Server on the same machine, if possible, would obviously reduce network latency issues.&lt;/font&gt;&lt;/p&gt;  &lt;/blockquote&gt;  &lt;h3&gt;6) Screen methods&lt;/h3&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2"&gt;If you are doing filtering of data in one of your screen methods, consider doing that on the server tier if possible.&amp;#160; That way, by filtering the data on the server side, you can reduce the amount of data that is sent across the network since that additional data that you filtered out won’t get sent over to the client now.&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font size="2"&gt;Another one to be careful of is the Screen_InitializeDataWorkspace() method.&amp;#160; Keep in mind that any code you run in that method has to complete before the any of the screen queries will be executed.&amp;#160; It can be a bit of a bottleneck if used incorrectly.&lt;/font&gt;&lt;/p&gt;  &lt;/blockquote&gt;  &lt;h3&gt;7) Profiling&lt;/h3&gt;  &lt;blockquote&gt;   &lt;h3&gt;&lt;font style="font-weight: normal;" size="2"&gt;Don't be afraid to use profilers to profile your client, and middle tier logic.&amp;#160; Use &lt;a href="http://technet.microsoft.com/en-us/library/ms181091.aspx" target="_blank"&gt;SQL profiler&lt;/a&gt; to analyze the queries you application is executing.&amp;#160; Use &lt;a href="http://www.fiddler2.com/fiddler2/" target="_blank"&gt;Fiddler&lt;/a&gt; to track the number of middle tier requests and the response sizes.&lt;/font&gt;&lt;/h3&gt;  &lt;/blockquote&gt;  &lt;h3&gt;8) Load Testing&lt;/h3&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2"&gt;Load testing is a great and easy way to get some data on how your LightSwitch application will perform in the real world.&amp;#160; &lt;a href="http://blogs.msdn.com/b/visualstudioalm/archive/2012/06/04/getting-started-with-load-testing-in-visual-studio-2012.aspx" target="_blank"&gt;Visual Studio Ultimate&lt;/a&gt; has some great tools for doing your own load testing (and there are a number of 3rd party tools as well).&lt;/font&gt;&lt;/p&gt;  &lt;/blockquote&gt;  &lt;h3&gt;9) Giant screens with lots of data&lt;/h3&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2"&gt;Probably obvious by this time, but keeping your LightSwitch screens small as possible, and not too complex will almost certainly help you avoid many a performance issue.&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h3&gt;10) Queries (the messy ones)&lt;/h3&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2"&gt;Queries can be difficult to get “right” sometimes.&amp;#160; They can be messy and just slow everything down.&amp;#160; That is a blog post by itself, and fortunately my smart co-worker Beth Massi has already written one &lt;img style="style" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/4380.wlEmoticon_2D00_smile_5F00_563E0500.png" /&gt; - check it out - &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2012/05/29/lightswitch-tips-amp-tricks-on-query-performance.aspx" target="_blank"&gt;LightSwitch Tips &amp;amp; Tricks on Query Performance&lt;/a&gt;.&lt;/font&gt;&amp;#160;&amp;#160; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;font size="2"&gt;That’s it for now.&amp;#160; We’ve been working on some awesome stuff here at the Fargo office, and I’m looking forward to blogging on that shortly.&amp;#160; But first I’ve got some more testing to do.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Let me know if this helps (or not).&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Thanks a lot – Matt Sampson &lt;img class="wlEmoticon wlEmoticon-martiniglass" alt="Martini glass" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/1263.wlEmoticon_2D00_martiniglass_5F00_5FEEA54E.png" /&gt;&lt;/font&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10381193" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/LightSwitch/">LightSwitch</category><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/Visual+Studio+2012/">Visual Studio 2012</category><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/Performance/">Performance</category></item><item><title>Finding Your LightSwitch Produced OData Services (Visual Studio 2012)</title><link>http://blogs.msdn.com/b/rmattsampson/archive/2012/06/13/where-s-my-lightswitch-odata-endpoint.aspx</link><pubDate>Wed, 13 Jun 2012 18:31:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10319482</guid><dc:creator>Matt Sampson</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/rmattsampson/rsscomments.aspx?WeblogPostID=10319482</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/rmattsampson/commentapi.aspx?WeblogPostID=10319482</wfw:comment><comments>http://blogs.msdn.com/b/rmattsampson/archive/2012/06/13/where-s-my-lightswitch-odata-endpoint.aspx#comments</comments><description>&lt;p&gt;&lt;font size="2"&gt;With the latest version of &lt;/font&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/hh852657"&gt;&lt;font size="2"&gt;LightSwitch in Visual Studio 2012&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt; you can now consume as well as produce &lt;/font&gt;&lt;a href="http://www.odata.org"&gt;&lt;font size="2"&gt;OData services&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt; from the data sources managed by the LightSwitch middle-tier.&amp;#160; But if we want to interact with the OData services that LightSwitch produces we need to know how to reference them directly.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;We’re going to learn how to do this today with a custom Silverlight control for our LightSwitch applications to help us easily view the OData service that LightSwitch produces for each data source on our application.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;(If you want some more detailed info on how LightSwitch makes and uses OData services, then John Rivard has a good article on just how LightSwitch uses OData services - &lt;a href="http://blogs.msdn.com/b/lightswitch/archive/2012/03/22/lightswitch-architecture-odata.aspx"&gt;LightSwitch Architecture: OData&lt;/a&gt;).&lt;/font&gt;&lt;/p&gt;  &lt;h2&gt;Where is my OData Service?&lt;/h2&gt;  &lt;p&gt;&lt;font size="2"&gt;If I make a LightSwitch application with a couple of data sources, like NorthwindData and ApplicationData, and build then we will have two OData services that will be automatically created for us.&amp;#160; These OData services will be named: NorthwindData.svc and ApplicationData.svc.&amp;#160; This is the important bit - &lt;strong&gt;each data source gets its own OData service. &lt;/strong&gt; The diagram below illustrates this well:&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3513.image_5F00_thumb_5F00_681635BF.png" width="350" height="241" /&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;These OData services are used by the LightSwitch client to communicate with the LightSwitch server.&amp;#160; But maybe you want to query these OData services directly yourself with your own OData client (like &lt;a href="http://www.microsoft.com/en-us/bi/powerpivot.aspx" target="_blank"&gt;Power Pivot&lt;/a&gt; for example), or maybe you’re just curious what these services look like.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;If you launch a published LightSwitch web application you will see the url look something like: &lt;/font&gt;&lt;font size="2"&gt;&lt;a href="http://MyServer/MyLightSwitchApplication/"&gt;http://MyServer/MyLightSwitchApplication/&lt;/a&gt;. And if you wanted to directly query the OData service for the Northwind data source directly you could just modify the url like so: &lt;a href="http://MyServer/MyLightSwitchApplication/NorthwindData.svc/"&gt;http://MyServer/MyLightSwitchApplication/NorthwindData.svc/&lt;/a&gt;. &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;As you can see, the format for referencing the OData service is http:// + server name + application name + OData service name:&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;To know what the OData service name is however, you would need to know the data source names.&amp;#160; You probably don’t have this knowledge unless you were the developer of the data model, and even then perhaps you’ve published your LightSwitch application several months ago and now you no longer recall the data source names.&lt;/font&gt;&lt;/p&gt;  &lt;h2&gt;Find it with a custom control&lt;/h2&gt;  &lt;p&gt;&lt;font size="2"&gt;We can simplify finding the LightSwitch produced OData service by creating a custom Silverlight control, adding it to our screen, then clicking a button to launch our OData service.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Our custom Silverlight control will utilize the LightSwitch API to determine what the name of our OData service is, and then it will launch a new browser window with the OData service as the URL. &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;If you haven’t used custom controls before, it just takes a few steps to add it to your screen.&lt;/font&gt;&amp;#160; &lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;1) Follow the basic steps over on my Code Gallery post, &lt;a href="http://code.msdn.microsoft.com/Visual-Studio-2012-Custom-625874bd" target="_blank"&gt;Custom Silverlight Control to find LightSwitch OData Services&lt;/a&gt;, to build the custom Silverlight Control into a .dll that we will use later&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;2) Create a LightSwitch Web application, add some data and add a screen (I created a table called “MyBook” to the ApplicationData data source)&lt;/font&gt;&amp;#160; &lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;3) Add a screen&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;4) Add a custom control to the screen like so:&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;strong&gt;Step 1 – &lt;/strong&gt;Select Add –&amp;gt; New Custom Control-&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/7331.image_5F00_70268290.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/4101.image_5F00_thumb_5F00_36A37299.png" width="270" height="274" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;strong&gt;Step 2 –&lt;/strong&gt; A dialog pops up asking where the custom control is. Click “Add Reference”.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/4606.image_5F00_1D3B6F5F.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/0474.image_5F00_thumb_5F00_07DDB9F7.png" width="383" height="432" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;strong&gt;Step 3 –&lt;/strong&gt; Click the “Browse” button and find the .dll for the custom Silverlight control that you made in the beginning. Hit OK.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/2548.image_5F00_07718702.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/4188.image_5F00_thumb_5F00_1BF6D680.png" width="506" height="352" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;strong&gt;Step 4 –&lt;/strong&gt; Expand the reference that was added to select the actual custom control name. Hit OK.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/1462.image_5F00_348673D0.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/2134.image_5F00_thumb_5F00_3F43CB25.png" width="423" height="502" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;strong&gt;Step 5 –&lt;/strong&gt; You can modify the control’s properties to give it a name like “OData Service:” as I did below:&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/7737.image_5F00_1AB23DA1.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/3515.image_5F00_thumb_5F00_535CE7AE.png" width="514" height="268" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;strong&gt;Step 6 –&lt;/strong&gt; F5 it!&amp;#160; You’ll see the control at runtime on your screen.&amp;#160; Click the drop down arrow to see a list of your OData services that are available to you.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/0044.image_5F00_1045D719.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/2626.image_5F00_thumb_5F00_6F526471.png" width="553" height="331" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;And viola!&amp;#160; A new browser window opens up with your OData service.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/3000.image_5F00_07E201C2.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/0044.image_5F00_thumb_5F00_1C675140.png" width="557" height="207" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;&amp;#160;&lt;/h2&gt;  &lt;h2&gt;Quick look at the code&lt;/h2&gt;  &lt;p&gt;&lt;font size="2"&gt;Let’s take a look at the Silverlight custom control code.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;In the constructor code below, which is invoked when the control is created, we are doing a few things:&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;1) We are looking through the list of Modules available to the client.&amp;#160; The one we want specifically is called LightSwitchCommonModule&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;2) We get all the EntityContainers off of the LightSwitchCommonModule and store them in a List object which we wil use later.&amp;#160; An EntityContainer will be our data source (e.g. ApplicationData, NorthwindData, etc.)&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;3) The List object we populated with Data Source names is bound to the custom Silverlight control.&amp;#160; That is the data the user will see at runtime available as a drop down list.&lt;/font&gt;&lt;/p&gt;  &lt;div style="margin: 0px; padding: 0px; float: none; display: inline;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:25a97613-d93e-460a-90fc-986f62152225" class="wlWriterSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Control Constructor&lt;/div&gt; &lt;div style="background: #fff; max-height: 500px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; ODataFinder()&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;InitializeComponent();&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;try&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;IModuleDefinition&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; module = &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;ClientApplicationProvider&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.Current.Details.GetModules().Where(i =&amp;gt; i.Name.Contains(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;LightSwitchCommonModule&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)).First();&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#008000"&gt;// EntityContainer objects will be things such as ApplicationData, NorthwindData,...&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;foreach&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (LightSwitch.&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;EntityContainer&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; globalItem &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;in&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; module.GlobalItems.OfType&amp;lt;LightSwitch.&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;EntityContainer&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&amp;gt;())&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;ServicesDropDownList.Items.Add(globalItem.Name);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;catch&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;Exception&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#008000"&gt;// if we fail then we just won&amp;#39;t populate any data sources&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Our custom control is a drop down list.&amp;#160; When the drop down is closed we will try to launch the OData service URL in a browser.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;This method below does that in the following way:&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;1) Get the URI of the Host machine, which will be something like “http://myServer/myApp/App.xap”&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;2) We parse off the name of the Host machine, and the name of the application&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;3) We combine the host name + the application name + the data source name selected by the user to form a URL.&amp;#160; Something like &lt;a href="http://myServer/myApp/ApplicationData.svc/"&gt;http://myServer/myApp/ApplicationData.svc/&lt;/a&gt;.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;4) We launch the URL in a web browser (the way we launch it in a web browser varies a bit on whether or not we are in a Desktop client or a Web client)&lt;/font&gt;&lt;/p&gt;  &lt;div style="margin: 0px; padding: 0px; float: none; display: inline;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:42dbedbb-6f7e-4102-8fef-f528015a2fe9" class="wlWriterSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Control Closed Method&lt;/div&gt; &lt;div style="background: #fff; max-height: 500px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;private&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;void&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; ServicesDropDownList_DropDownClosed(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;object&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; sender, &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;EventArgs&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; e)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;try&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; absoluteUri = &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;Application&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.Current.Host.Source.AbsoluteUri;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;System.&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;UriBuilder&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; appUri = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;UriBuilder&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;(absoluteUri);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; host = &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;Application&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.Current.Host.Source.Host;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;int&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; indexOfHost = absoluteUri.IndexOf(host);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;int&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; indexOfEndOfHost = absoluteUri.IndexOf(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;/&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, indexOfHost + host.Length);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; dataServiceUri = absoluteUri.Substring(0, indexOfEndOfHost);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (host.Contains(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;localhost&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;))&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;dataServiceUri = dataServiceUri + &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;/&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; + ServicesDropDownList.SelectedItem.ToString() + &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;.svc&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; + &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;/&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;else&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#008000"&gt;//Example format: http://IISMachine/AppName/Web/Application18.Client.xap?v=1.0.2.0?v=1.0.2.0&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;int&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; indexOfEndOfAppName = absoluteUri.IndexOf(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;/&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, indexOfEndOfHost + 2);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;int&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; lengthOfAppName = indexOfEndOfAppName - indexOfEndOfHost;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; appName = absoluteUri.Substring(indexOfEndOfHost, lengthOfAppName);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;dataServiceUri = dataServiceUri + appName + &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;/&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; + ServicesDropDownList.SelectedItem.ToString() + &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;.svc&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; + &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;/&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#008000"&gt;// Check to see if we are running in the Desktop&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;AutomationFactory&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.IsAvailable)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; shell = &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;AutomationFactory&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.CreateObject(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Shell.Application&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;shell.ShellExecute(dataServiceUri);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#008000"&gt;// Else we are running in a web client&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;else&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#008000"&gt;//Open up the OData service in a new web page&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;System.Windows.Browser.&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;HtmlPage&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.Window.Navigate(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;Uri&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;(dataServiceUri), &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;_blank&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;catch&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;Exception&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#008000"&gt;// if we fail then just don&amp;#39;t display anything&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h2&gt;Bring it all together&lt;/h2&gt;  &lt;p&gt;&lt;font size="2"&gt;We’ve covered a couple things here: &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;a) H&lt;/font&gt;&lt;font size="2"&gt;ow you can go about manually finding your OData services that LightSwitch produces for each data source&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;b) How you can make this a bit easier by adding a custom Silverlight control your LightSwitch applications to find and display the OData service for you.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Check out my Ccode Gallery post, &lt;a href="http://code.msdn.microsoft.com/Visual-Studio-2012-Custom-625874bd" target="_blank"&gt;Custom Silverlight Control to find LightSwitch OData Services&lt;/a&gt;, for the code and for some more details on how to make this custom SL control.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Thanks all, and please let me know if you have any feedback.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;-Matt Sampson &lt;img class="wlEmoticon wlEmoticon-martiniglass" alt="Martini glass" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/6114.wlEmoticon_2D00_martiniglass_5F00_7D336C82.png" /&gt;&lt;/font&gt;&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:right; margin:0px; padding:4px 0px 4px 0px;"&gt;&lt;a href="http://digg.com/submit?url=http%3a%2f%2fblogs.msdn.com%2fb%2frmattsampson%2farchive%2f2012%2f06%2f13%2fwhere-s-my-lightswitch-odata-endpoint.aspx&amp;amp;title=Finding+Your+LightSwitch+Produced+OData+Services+(Visual+Studio+2012)"&gt;&lt;img src="http://digg.com/img/badges/100x20-digg-button.png" width="100" height="20" alt="Digg This" title="Digg This" border="0" style="border: 0" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10319482" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/LightSwitch/">LightSwitch</category><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/SilverLight/">SilverLight</category><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/Custom+Controls/">Custom Controls</category><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/Visual+Studio+2012/">Visual Studio 2012</category><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/OData+Services/">OData Services</category></item><item><title>OData Apps in LightSwitch (With Custom RIA Data Sources and Many to Many!), Part 3</title><link>http://blogs.msdn.com/b/rmattsampson/archive/2012/04/30/odata-apps-in-lightswitch-part-3.aspx</link><pubDate>Mon, 30 Apr 2012 13:49:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10299075</guid><dc:creator>Matt Sampson</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/rmattsampson/rsscomments.aspx?WeblogPostID=10299075</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/rmattsampson/commentapi.aspx?WeblogPostID=10299075</wfw:comment><comments>http://blogs.msdn.com/b/rmattsampson/archive/2012/04/30/odata-apps-in-lightswitch-part-3.aspx#comments</comments><description>&lt;p&gt;&lt;strong&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;&lt;span&gt;Update again: &lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;Attaching to a database to m&lt;/span&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;any to many relationships is now supported (in Visual Studio 2012 RTM) and the relationships will display in the entity designer just like any other relationship.&amp;nbsp; As a result it's possible to do the below scenario without a RIA Data Source and instead just use LightSwitch built in functionality.&lt;/span&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;&lt;span&gt;Update: &lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;&lt;span&gt;I've posted the sample application in the MSDN Code Gallery here - &lt;a href="http://code.msdn.microsoft.com/Consuming-OData-in-7df2ef7b"&gt;http://code.msdn.microsoft.com/Consuming-OData-in-7df2ef7b&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;&lt;span&gt;--------------------------------------------------------------&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;&lt;span&gt;Welcome back!&amp;nbsp; In this post we are going to wrap up the OData application we started back in &lt;/span&gt;&lt;a href="http://blogs.msdn.com/b/rmattsampson/archive/2012/03/19/odata-apps-in-lightswitch.aspx" target="_blank"&gt;&lt;span&gt;Part 1&lt;/span&gt;&lt;/a&gt;&lt;span&gt; and continued in &lt;a href="http://blogs.msdn.com/b/rmattsampson/archive/2012/04/02/odata-apps-in-lightswitch-part-2.aspx" target="_blank"&gt;Part 2&lt;/a&gt;.&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;To refresh everyone on how we got here, we started with the idea that we would use some new features in LightSwitch for Visual Studio 11 (Beta) that would allow us to attach to an OData service.&amp;nbsp; Specifically we are attaching to the &lt;a href="http://www.commuterapi.com/" target="_blank"&gt;Commuter API&lt;/a&gt; &lt;a href="http://transit.cloudapp.net/DevTransitODataService.svc/" target="_blank"&gt;OData service&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;We wanted to solve 4 basic problems:&lt;/span&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;Where is my stop? (we solved this in Part 1 and 2 with a Bing maps extension)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;When is my train arriving? (we solved this in Part 1)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;How do I get there? (we solved this in Part 1 and 2 with Route information and maps)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;How many escalators will be broken today? (we saved this problem for Part 3)&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;To find a solution to this last problem we are going to pull in data from the &amp;ldquo;Incidents&amp;rdquo; entity in the OData service.&amp;nbsp; This entity contains all the information regarding broken escalators and things of that nature.&lt;/span&gt;&lt;/p&gt;
&lt;h1&gt;Retrieving &amp;ldquo;Incidents&amp;rdquo; data&lt;/h1&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;If we open up our OData app and look at the Incidents entity in the Entity Designer, it should look like this:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/0638.image_5F00_464161A5.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/0245.image_5F00_thumb_5F00_30E3AC3D.png" alt="image" width="399" height="267" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;Note: If you don&amp;rsquo;t have the Incidents entity in your entity designer, then right click on the TransitDataData data source and select &amp;ldquo;Update data source&amp;rdquo;.&amp;nbsp; Then you will be able to import the Incidents entity.&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;You can see we don&amp;rsquo;t have any relationships on this entity.&amp;nbsp; There are indeed relationships defined on this entity in the OData Service, but they are all &amp;ldquo;many to many&amp;rdquo; relationships.&amp;nbsp; And LightSwitch does not provide support for many to many relationships out of the box.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;That&amp;rsquo;s too bad, but it&amp;rsquo;s not a deal breaker.&amp;nbsp; I would really like to relate the Incident data with our Stops data so that on our Stops List and Detail screen we could show all the incidents related to that stop (for example, the Metro Center stop has a broken escalator, and trains are all delayed because of snow).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;Fortunately for us we can still make this work and pull in information for the Incidents entity and relate it to a specific Stop by creating a Custom RIA Data source.&amp;nbsp; In general, Custom RIA Data Sources are beneficial for a wide array of problems, like &lt;a href="http://blogs.msdn.com/b/lightswitch/archive/2011/04/08/how-do-i-display-a-chart-built-on-aggregated-data-eric-erhardt.aspx" target="_blank"&gt;aggregating data&lt;/a&gt;. Our custom RIA data source is going to enable us to create our own query to pull in the Incidents data from the Transit Data OData service and relate it with a corresponding Stop.&lt;/span&gt;&lt;/p&gt;
&lt;h1&gt;Custom RIA Data Source &amp;ndash; Creation&lt;/h1&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;Let&amp;rsquo;s get started on making our basic Custom RIA data source.&amp;nbsp; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;First of all, make sure, in Visual Studio, under Tools &amp;ndash;&amp;gt; Options &amp;ndash;&amp;gt; Projects and Solutions that you have the &amp;ldquo;Always show solution&amp;rdquo; checkbox checked.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;Now, right click on your solution and select Add &amp;ndash;&amp;gt; New Project. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;Let&amp;rsquo;s just add a &amp;ldquo;Class Library&amp;rdquo; (I&amp;rsquo;m using a C# Class Library because my LightSwitch project is a C# project).&amp;nbsp; Call the new project &amp;ldquo;RiaService&amp;rdquo; and click OK.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;In our new project, double click on the &amp;ldquo;Properties&amp;rdquo; icon and change the Target Framework to .NET Framework 4.0.&amp;nbsp; This will be important later on when we try to attach to our Custom RIA data source (I&amp;rsquo;ll explain when we get there).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;&lt;span&gt;Now right click our new project and select Add &amp;ndash;&amp;gt; New Item. Select Visual C# Items &amp;ndash;&amp;gt; Web &amp;ndash;&amp;gt; Domain Service Class.&amp;nbsp; Call it TransitData and hit OK.&amp;nbsp; The only reason why I chose this file type is because it automatically adds a bunch of project references that we are going to need (you certainly could have just selected a basic Class file and added the references yourself).&amp;nbsp; &lt;/span&gt;&lt;span&gt;We still need to add one more reference to our project. So right click the References node and select Add Reference.&amp;nbsp; Add a reference to System.Data.Services.Client.dll.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;Your list of References should look like this:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/1882.image_5F00_76AAE48B.png"&gt;&lt;img style="margin: 0px; display: inline; background-image: none;" title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/4213.image_5F00_thumb_5F00_2ADF0DD2.png" alt="image" width="244" height="188" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;Now we need to add a service reference to the Transit Data OData service.&amp;nbsp; Right click the References node again and select &amp;ldquo;Add Service Reference&amp;rdquo; and use this OData service - &lt;a title="http://transit.cloudapp.net/DevTransitODataService.svc" href="http://transit.cloudapp.net/DevTransitODataService.svc"&gt;http://transit.cloudapp.net/DevTransitODataService.svc&lt;/a&gt; (this is of course the same one that we attached to with our LightSwitch application in Part 1).&amp;nbsp; Call the namespace TransitDataServiceReference.&amp;nbsp; It &lt;/span&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;should look something like this -&lt;/span&gt; &lt;br /&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/3652.image_5F00_7C858824.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/0312.image_5F00_thumb_5F00_631D84EA.png" alt="image" width="357" height="293" border="0" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;Once you hit OK it will attach to that OData service and generate code for the corresponding entities in the service.&amp;nbsp; You&amp;rsquo;ll see now in a minute how we have an Incidents entity available to us in our custom RIA data service project.&amp;nbsp; It&amp;rsquo;s important to understand that we are in NO way using any code right now from our LightSwitch project, or am I referring to the Incidents entity that is available in our LightSwitch project under the TransitDataData source.&amp;nbsp; The Transit Data service that we just attached to and the Incidents entity that we have generated code for is specific to this RIA project.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;At this point we have a basic custom RIA data service.&amp;nbsp; We just have to add a bit of code at this point before we can add the RIA service to LightSwitch as a data source.&lt;/span&gt;&lt;/p&gt;
&lt;h1&gt;Custom RIA Data Source &amp;ndash; Adding Code&lt;/h1&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;Let&amp;rsquo;s add some code now to the TransitData.cs file.&amp;nbsp; Copy and paste the below code into your file:&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:99d4d1ea-6aed-4dcd-813c-3915786f5628" class="wlWriterSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"&gt;
&lt;div style="background: #fff; max-height: 300px; overflow: auto;"&gt;&lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt;
&lt;li&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;using&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; System;&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;using&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; System.Collections.Generic;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;using&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; System.ComponentModel;&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;using&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; System.ComponentModel.DataAnnotations;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;using&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; System.Linq;&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;using&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; System.ServiceModel.DomainServices.Hosting;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;using&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; System.ServiceModel.DomainServices.Server;&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;using&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; RIAService.TransitDataServiceReference;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;namespace&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; RIAService&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;{&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #0000ff;"&gt;public&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;class&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;TransitDomainService&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; : &lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;DomainService&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;{&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;[&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;Query&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;(IsDefault = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;true&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;)]&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #0000ff;"&gt;public&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;IQueryable&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;Incident&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;&amp;gt; GetIncidents()&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;{&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #0000ff;"&gt;return&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;null&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;;&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;}&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;[&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;Query&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;]&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #0000ff;"&gt;public&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;IQueryable&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;Incident&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;&amp;gt; GetIncidentsByStop(&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;string&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; stopId)&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;{&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #2b91af;"&gt;TransitData&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; myTransitData = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;new&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;TransitData&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;(&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;new&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;Uri&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;(&lt;/span&gt;&lt;span style="background: #ffffff; color: #800000;"&gt;"http://transit.cloudapp.net/DevTransitODataService.svc"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;));&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #0000ff;"&gt;return&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; myTransitData.Stops.Where(s =&amp;gt; s.StopId == stopId).SelectMany(s =&amp;gt; s.Incidents);&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;}&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;}&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;}&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;namespace&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; RIAService.TransitDataServiceReference&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;{&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;[&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;MetadataType&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;(&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;typeof&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;(&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;Metadata&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;))]&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #0000ff;"&gt;public&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;partial&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;class&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;Incident&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;{&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #0000ff;"&gt;public&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;class&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;Metadata&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;{&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;[&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;Key&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;]&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #0000ff;"&gt;public&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;string&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; IncidentId&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;{&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #0000ff;"&gt;get&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;;&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #0000ff;"&gt;set&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;}&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;}&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;}&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;}&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;That&amp;rsquo;s it for code that we&amp;rsquo;ll need to write.&amp;nbsp; Now let&amp;rsquo;s go over it: &lt;br /&gt;Note how we have a &amp;ldquo;using TransitDataServiceReference&amp;rdquo; statement at the top.&amp;nbsp; When we generated code for our service reference that we added we put all that code under the TransitDataServiceReference namespace.&amp;nbsp; This will allow us to directly reference the Incident entity and the TransitData class.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;For a custom RIA data service we need to have a default query type which is what the GetIncidents() method is.&amp;nbsp; This query would typically be the &amp;ldquo;All&amp;rdquo; query or the query that returns all of the records for the entity.&amp;nbsp; For our purposes we don&amp;rsquo;t need to do anything more than just return null here.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;The GetIncidentsByStop() method we define as a &amp;ldquo;Query&amp;rdquo; as well.&amp;nbsp; This means that when we attach to this RIA Data service through LightSwitch that this query will show up in the Query designer.&amp;nbsp; This is really the query that&amp;rsquo;s going to do all our work.&amp;nbsp; The code in this method is: &lt;/span&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;Creating a new instance of the TrainsitData data service (for which you have to pass in the Uri to the actual OData service)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;Querying on all of the &amp;ldquo;Stops&amp;rdquo; and retrieving all the Incidents that have a &amp;ldquo;StopId&amp;rdquo; corresponding to the &amp;ldquo;stopId&amp;rdquo; that was passed into the method.&amp;nbsp; (For example, if we pass in the Metro Center stop it will retrieve all the Incidents that are related to that stop).&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;Those incidents related to the stopId are then returned&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;At the bottom of the code snippet you&amp;rsquo;ll notice that we have a separate class.&amp;nbsp; The Incidents entity that was generated does not have a primary key defined on it.&amp;nbsp; We are going to need one before we try to attach to this RIA data service with LightSwitch.&amp;nbsp; So we need to specify which field is the primary key, which is all we are doing here.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;Extending upon the &amp;ldquo;Incident&amp;rdquo; class that was generated we define an inner class called Metadata.&amp;nbsp; Then we specify that the IncidentId property is the primary key by giving it the &amp;ldquo;Key&amp;rdquo; attribute.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;More information on partial classes: &lt;a href="http://msdn.microsoft.com/en-us/library/wa80x488(v=vs.110).aspx"&gt;Partial Classes and Methods (C# Programming Guide)&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/yfzd5350.aspx"&gt;Partial (Visual Basic)&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;More information on creating a metadata class for RIA services: &lt;a href="http://msdn.microsoft.com/en-us/library/ee707339%28v=VS.91%29.aspx"&gt;How to Add Metadata Classes&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;More information on the &amp;ldquo;Key&amp;rdquo; attribute: &lt;a href="http://blogs.infosupport.com/a-guide-through-wcf-ria-services-attributes/"&gt;A guide through WCF RIA Services attributes&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h1&gt;Add Our RIA Data Source&lt;/h1&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;Go ahead and build our RIAService project.&amp;nbsp; Remember we made our RIA project target the .Net 4.0 framework?&amp;nbsp; That was important otherwise you will get an error when trying to attach to it here, since the LightSwitch project is also targeting the .NET 4.0 Framework.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;Open up the LightSwitch project, and let&amp;rsquo;s add this data source to it, like so:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/3542.image_5F00_62B151F5.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/5706.image_5F00_thumb_5F00_103271B9.png" alt="image" width="313" height="248" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If the RIA service doesn&amp;rsquo;t show up here, then select Add Reference &amp;ndash;&amp;gt; Solution &amp;ndash;&amp;gt; Projects and select the RIAService project.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/2465.image_5F00_61D8EC0B.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/4520.image_5F00_thumb_5F00_337F665E.png" alt="image" width="319" height="252" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;Click Next, select all the entities and queries (there should only be the Incidents entity and GetIncidentsByStop query).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;We should now have the data source, entity and query in our designer:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/4213.image_5F00_4804B5DC.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/1586.image_5F00_thumb_5F00_20CA6CA7.png" alt="image" width="212" height="61" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;Modify our Stops List and Detail Screen&lt;/h1&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;We&amp;rsquo;ll need to modify our Stops List and Detail screen now to include the Incidents information that we want (my screen is specifically called StopsDCMetroListDetail).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;Double click on our screen to bring it up in the screen designer.&amp;nbsp; With the screen designer open, select &amp;ldquo;Add Data Item&amp;hellip;&amp;rdquo; and select the GetIncidentsByStop query like so:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/6607.image_5F00_597516B4.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/3542.image_5F00_thumb_5F00_6DFA6632.png" alt="image" width="383" height="303" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;Hit OK and it will be added to the screen designer.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;Now drag and drop the data for GetIncidentsByStop onto our screen so that it looks like this:&lt;/span&gt;&lt;/p&gt;
&lt;table style="width: 400px;" border="0" cellspacing="0" cellpadding="2"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" width="200"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/0815.image_5F00_068A0383.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/5127.image_5F00_thumb_5F00_3F34AD90.png" alt="image" width="219" height="244" border="0" /&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td valign="top" width="200"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/1805.image_5F00_6CB5CD53.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/1411.image_5F00_thumb_5F00_106EF4EE.png" alt="image" width="209" height="377" border="0" /&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;Now we&amp;rsquo;ll need to bind our stopId query parameter to whatever Stop we currently have selected on our screen.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;So, double click on the stopId query parameter, and then in the &amp;ldquo;Properties&amp;rdquo; window bind it to StopsDCMetro.SelectedItem.StopId so that it looks like this:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/3252.image_5F00_7A081A82.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/1682.image_5F00_thumb_5F00_799BE78D.png" alt="image" width="244" height="204" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This effectively says that the &amp;ldquo;stopId&amp;rdquo; query parameter is going to be equal to whatever Stop we currently have selected on our screen.&lt;/p&gt;
&lt;p&gt;And that is it! Save it, and re-build the solution.&lt;/p&gt;
&lt;h1&gt;F5 IT!&lt;/h1&gt;
&lt;p&gt;F5 it and open up the Stops DC Metro List and Detail screen.&amp;nbsp; You should see a list of Incidents beneath the Details for the Stop.&amp;nbsp; So it will look something like this now:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/1157.image_5F00_072E4E5F.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/1157.image_5F00_thumb_5F00_16EDE363.png" alt="image" width="587" height="368" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;You can see in this instance that not even the Pentagon is immune to the ubiquitous broken escalator problem.&lt;/span&gt;&lt;/p&gt;
&lt;h1&gt;Wrapping it Up&lt;/h1&gt;
&lt;p&gt;To summarize what we&amp;rsquo;ve done here, I showed you how to create a RIA Service wrapper around a data source that has many to many relationships.&amp;nbsp; We specifically utilized this RIA Service to relate data between the Stops and the Incidents entity (so that we can tell how many escalators will be busted at our Metro stop).&lt;/p&gt;
&lt;p&gt;That pretty much does it for our OData sample app.&amp;nbsp; I will be publishing all this code (C# and VB.NET) out on the &lt;a href="http://code.msdn.microsoft.com/" target="_blank"&gt;MSDN Code Gallery&lt;/a&gt; and will update the blog as soon as I have that done.&lt;/p&gt;
&lt;p&gt;Please let me know if you have any questions or requests for future topics.&lt;/p&gt;
&lt;p&gt;Thanks all!&lt;/p&gt;
&lt;p&gt;-Matt Sampson &lt;img class="wlEmoticon wlEmoticon-martiniglass" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/5850.wlEmoticon_2D00_martiniglass_5F00_36308A36.png" alt="Martini glass" /&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div class="wlWriterHeaderFooter" style="text-align: right; margin: 0px; padding: 4px 0px 4px 0px;"&gt;&lt;a href="http://digg.com/submit?url=http%3a%2f%2fblogs.msdn.com%2fb%2frmattsampson%2farchive%2f2012%2f04%2f30%2fodata-apps-in-lightswitch-part-3.aspx&amp;amp;title=OData+Apps+in+LightSwitch%2c+Part+3"&gt;&lt;img style="border: 0;" title="Digg This" src="http://digg.com/img/badges/100x20-digg-button.png" alt="Digg This" width="100" height="20" border="0" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10299075" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/LightSwitch/">LightSwitch</category><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/OData/">OData</category><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/RIA/">RIA</category></item><item><title>OData Apps In LightSwitch, Part 2</title><link>http://blogs.msdn.com/b/rmattsampson/archive/2012/04/02/odata-apps-in-lightswitch-part-2.aspx</link><pubDate>Mon, 02 Apr 2012 16:16:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10289985</guid><dc:creator>Matt Sampson</dc:creator><slash:comments>7</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/rmattsampson/rsscomments.aspx?WeblogPostID=10289985</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/rmattsampson/commentapi.aspx?WeblogPostID=10289985</wfw:comment><comments>http://blogs.msdn.com/b/rmattsampson/archive/2012/04/02/odata-apps-in-lightswitch-part-2.aspx#comments</comments><description>&lt;p&gt;&lt;font size="2"&gt;Hey All,&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;I wanted to continue making some improvements to the OData Application we started in my last post &lt;a href="http://blogs.msdn.com/b/rmattsampson/archive/2012/03/19/odata-apps-in-lightswitch.aspx" target="_blank"&gt;OData Apps in LightSwitch, Part 1&lt;/a&gt; (which also has the sample project &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-28-51-28/MyDCAppVB.zip" target="_blank"&gt;uploaded in VB.NET now&lt;/a&gt;).&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;At the end of the last post we had: attached to a public OData feed and pulled in data for the DC Metro, we showed off some new data types, and we utilized caching on our computed fields to improve performance.&amp;#160; We also added queries to narrow down our data.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;There are still a few things we should wrap up on before finishing up:&lt;/font&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;font size="2"&gt;Add some automatic refreshing to our Arrivals screen&lt;/font&gt;&lt;/li&gt;    &lt;li&gt;&lt;font size="2"&gt;Customize the “Stops” screen so that it can provide us with a map of the Stops location&lt;/font&gt;&lt;/li&gt;   &lt;font size="2"&gt;&lt;/font&gt;    &lt;li&gt;&lt;font size="2"&gt;Hook up the Incidents entity so that we can pull in data regarding all the busted escalators (and DC has a lot of them)&lt;/font&gt;&lt;/li&gt;  &lt;/ol&gt;  &lt;p&gt;&lt;font size="2"&gt;Let’s kick this off first by adding some automatic refreshing to our Arrivals List and Details screen.&lt;/font&gt;&lt;/p&gt;  &lt;h1&gt;Adding Auto Refresh&lt;/h1&gt;  &lt;p&gt;&lt;font size="2"&gt;We should have an Arrivals screen that looks something like this:&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font size="2"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/3264.OldArrivals_5F00_6ABFED3E.png"&gt;&lt;img style="display: inline; background-image: none;" title="OldArrivals" border="0" alt="OldArrivals" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/2768.OldArrivals_5F00_thumb_5F00_49CC7A97.png" width="497" height="175" /&gt;&lt;/a&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;This data is updated in real time, but our screen is not updated real time.&amp;#160; It’d be nice to not have to hit the “refresh” button every time we want to see new train information.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;We can add our own Auto Refresh functionality pretty easily as you will see.&lt;/font&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;font size="2"&gt;Open up the Arrivals screen in the screen designer (should be called MetroByArrivalTimeListDetail)&lt;/font&gt;&lt;/li&gt;    &lt;li&gt;&lt;font size="2"&gt;Right click the screen in the Solution Explorer, and select select “View Screen Code”&lt;/font&gt;&lt;/li&gt;    &lt;li&gt;&lt;font size="2"&gt;We should now be in the code editor&lt;/font&gt;&lt;/li&gt;    &lt;li&gt;&lt;font size="2"&gt;Add a using statement for the System.Threading since we will need to use some classes from that namespace&lt;/font&gt;&lt;/li&gt;   &lt;font size="2"&gt;&lt;/font&gt;    &lt;li&gt;&lt;font size="2"&gt;Copy and paste the below code into your screen’s class&lt;/font&gt;&lt;/li&gt;  &lt;/ol&gt;  &lt;div style="margin: 0px; padding: 0px; float: none; display: inline;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4ca03d4c-f5db-43e1-9eae-7982584c4aab" class="wlWriterSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;private&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;Timer&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; myTimer;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;partial&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;void&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; MetroByArrivalTimeListDetail_Closing(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;ref&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;bool&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; cancel)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.myTimer.Dispose();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;partial&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;void&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; MetroByArrivalTimeListDetail_Created()&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;TimerCallback&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; tcb = MyCallBack;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.myTimer = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;Timer&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;(tcb);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;myTimer.Change(120000, 120000);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;void&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; MyCallBack(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;Object&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; stateInfo)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.Details.Dispatcher.BeginInvoke(() =&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.Refresh();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;font size="2"&gt;Let’s go through what we’re doing with this code.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;When our Arrival List and Details screen is created for the first time the Created() method gets invoked.&amp;#160; Inside of this method we start a &lt;a href="http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx" target="_blank"&gt;Timer&lt;/a&gt;.&amp;#160; When we construct the Timer object we pass in a &lt;a href="http://msdn.microsoft.com/en-us/library/system.threading.timercallback.aspx" target="_blank"&gt;TimerCallBack&lt;/a&gt; object which specifies the method to be invoked by the timer – in this case the method is “MyCallBack”.&amp;#160; The MyCallback method does the actual call to “Refresh” the screen.&amp;#160; Keep in mind that we have to switch to the logic dispatcher before we invoke the Refresh() method.&amp;#160; This is because Refresh() can only be invoked from the logic dispatcher, so we are simply making sure here that we are indeed on the logic dispatcher by doing a this.Details.Dispatcher.BeginInvoke() call.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Our Timer is set to be invoked after 120,000 milliseconds (which is = 2 minutes).&amp;#160; And then will be invoked again every 2 minutes after that, for as long as this screen is open.&amp;#160; When the screen is closed we will invoke the Closing() method which will make sure we are cleaning up after ourselves and will dispose of our object.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;If you F5 now, open up the Arrivals List and Details screen and wait 2 minutes you will see the auto refresh in action.&lt;/font&gt;&lt;/p&gt;  &lt;h1&gt;Adding Bing Maps&lt;/h1&gt;  &lt;p&gt;&lt;font size="2"&gt;For our next trick we are going to do something with the latitude and longitude properties that are displayed on the Stops List and Details screen.&amp;#160; We can beautify this a bit and show a map instead.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://code.msdn.microsoft.com/Contoso-Construction-338952fd" target="_blank"&gt;&lt;font size="2"&gt;Beth Massi has an awesome demo&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt; of her own on consuming OData, using the Bing Maps extension, and a dozen other things.&amp;#160; She also reminds us that if we are going to be using Bing Maps in our project we need to get a Bing Maps Key first.&amp;#160; As Beth says:&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;&lt;font size="2"&gt;Getting the key is a free and straightforward process you can complete by following these steps:&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;em&gt;&lt;font size="2"&gt;Go to the Bing Maps Account Center at &lt;/font&gt;&lt;/em&gt;&lt;a href="https://www.bingmapsportal.com"&gt;&lt;em&gt;&lt;font size="2"&gt;https://www.bingmapsportal.com&lt;/font&gt;&lt;/em&gt;&lt;/a&gt;&lt;em&gt;&lt;font size="2"&gt;. &lt;/font&gt;&lt;/em&gt;&lt;/li&gt;    &lt;li&gt;&lt;em&gt;&lt;font size="2"&gt;Click Sign In, to sign in using your Windows Live ID credentials. &lt;/font&gt;&lt;/em&gt;&lt;/li&gt;    &lt;li&gt;&lt;em&gt;&lt;font size="2"&gt;If you haven’t got an account, you will be prompted to create one. &lt;/font&gt;&lt;/em&gt;&lt;/li&gt;    &lt;li&gt;&lt;em&gt;&lt;font size="2"&gt;Enter the requested information and then click Save. &lt;/font&gt;&lt;/em&gt;&lt;/li&gt;    &lt;li&gt;&lt;em&gt;&lt;font size="2"&gt;Click the &amp;quot;Create or View Keys&amp;quot; link on the left navigation bar. &lt;/font&gt;&lt;/em&gt;&lt;/li&gt;    &lt;li&gt;&lt;em&gt;&lt;font size="2"&gt;Fill in the requested information and click &amp;quot;Create Key&amp;quot; to generate a Bing Maps Key.&lt;/font&gt;&lt;/em&gt;&lt;/li&gt;  &lt;/ul&gt;  &lt;p&gt;&lt;font size="2"&gt;Hang onto your Bing Maps Key, we’ll use it later.&lt;/font&gt;&amp;#160; &lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;The Bing Maps extension is a VSIX which you can find in the zip file &lt;a href="http://code.msdn.microsoft.com/Contoso-Construction-338952fd/file/54438/2/Contoso%20Construction%20-%20LightSwitch%20Advanced%20Sample%20(Visual%20Studio%2011%20Beta).zip" target="_blank"&gt;here&lt;/a&gt;.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Double click the VSIX file after you download the zip file to install the extension.&amp;#160; After installing the VSIX open up the Properties designer for our application and go to the “Extensions” tab.&amp;#160; We need to enable the Bing Maps extension now like this:&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/4478.image_5F00_40033715.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/5226.image_5F00_thumb_5F00_1EA39179.png" width="396" height="71" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Let’s go back to our Stops entity now in the entitiy designer.&lt;/font&gt;&lt;/p&gt;  &lt;font size="2"&gt;&lt;/font&gt;  &lt;p&gt;&lt;font size="2"&gt;Add a new string property to the Stops entity which will be a computed property.&amp;#160; Call it “Location”.&lt;/font&gt;&lt;/p&gt;  &lt;font size="2"&gt;&lt;/font&gt;  &lt;p&gt;&lt;font size="2"&gt;The Stops entity should look something like this now:&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/2318.image_5F00_46711D84.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/4784.image_5F00_thumb_5F00_50C241E4.png" width="461" height="183" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;In the Properties for Location, click the “Edit Method” button.&amp;#160; We should now be in the generated computed property method.&amp;#160; Copy the below code into the method:&lt;/font&gt;&lt;/p&gt;  &lt;div style="margin: 0px; padding: 0px; float: none; display: inline;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:09ef49b2-b8e1-4bfb-8384-47911068e503" class="wlWriterSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&gt; &lt;div style="background: #fff; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;partial&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;void&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; Location_Compute(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;ref&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; result)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;result = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.Lat + &lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;&amp;quot; &amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; + &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.Lon;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;font size="2"&gt;In this method we are setting up our Location computed property so that it’s value is the Latitude and Longitude coordinates of our Metro stop.&amp;#160; The value has to be Latitude followed by Longitude (if you invert it and make it Longitude followed by Latitude you will end up in Antarctica and will completely miss your train).&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Now open up our StopsDCMetroListDetail screen.&amp;#160; We’ll add in the Location property now to this screen.&amp;#160; (&lt;font size="2"&gt;I dragged and dropped it onto the screen). &lt;/font&gt;And then click on the drop down arrow for the property and switch it to “Bing Map Control”.&amp;#160; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/4375.image_5F00_1DF23B70.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/8078.image_5F00_thumb_5F00_5D4FEF00.png" width="219" height="304" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;On the property sheet for the Location field you should see an option for the Bing Maps Keys. You’ll need to paste in the value here that you got from the &lt;/font&gt;&lt;a href="http://www.bingmapsportal.com"&gt;&lt;font size="2"&gt;http://www.bingmapsportal.com&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt; site.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;At this point we should be ready to F5.&lt;/font&gt;&lt;/p&gt;  &lt;h1&gt;Check it out&lt;/h1&gt;  &lt;p&gt;&lt;font size="2"&gt;We should now have an Arrivals List and Details screen that auto refreshes every couple minutes, and a Stops List and Details screen that shows us a map of where our Metro stop is located. &lt;/font&gt;&lt;/p&gt;  &lt;font size="2"&gt;&lt;/font&gt;  &lt;p&gt;&lt;font size="2"&gt;Our Stops List and Details screen now:&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/1072.image_5F00_589C6C77.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/2727.image_5F00_thumb_5F00_241B9A2F.png" width="401" height="193" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;I still want to pull in information for the “Incidents” entity so that we can keep track of all the busted escalators.&lt;/font&gt;&lt;/p&gt; &lt;font size="2"&gt;&lt;/font&gt;  &lt;p&gt;&lt;font size="2"&gt;To do this will involve a blog post just by itself, since we will need to do some low level technical things to pull in all that information.&amp;#160; But after we do that I think we’ll be able to navigate the DC Metro system with confidence.&amp;#160; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Thanks for reading and let me know if you have any questions.&lt;/font&gt;&lt;/p&gt; &lt;font size="2"&gt;&lt;/font&gt;  &lt;p&gt;&lt;font size="2"&gt;– Matt Sampson &lt;img class="wlEmoticon wlEmoticon-martiniglass" alt="Martini glass" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/8231.wlEmoticon_2D00_martiniglass_5F00_3D2AB86A.png" /&gt;&lt;/font&gt;&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:right; margin:0px; padding:4px 0px 4px 0px;"&gt;&lt;a href="http://digg.com/submit?url=http%3a%2f%2fblogs.msdn.com%2fb%2frmattsampson%2farchive%2f2012%2f04%2f02%2fodata-apps-in-lightswitch-part-2.aspx&amp;amp;title=OData+Apps+In+LightSwitch%2c+Part+2"&gt;&lt;img src="http://digg.com/img/badges/100x20-digg-button.png" width="100" height="20" alt="Digg This" title="Digg This" border="0" style="border: 0" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10289985" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/LightSwitch/">LightSwitch</category><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/OData/">OData</category><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/Visual+Studio+11+Beta/">Visual Studio 11 Beta</category></item><item><title>OData Apps In LightSwitch, Part 1</title><link>http://blogs.msdn.com/b/rmattsampson/archive/2012/03/19/odata-apps-in-lightswitch.aspx</link><pubDate>Mon, 19 Mar 2012 21:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10285128</guid><dc:creator>Matt Sampson</dc:creator><slash:comments>7</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/rmattsampson/rsscomments.aspx?WeblogPostID=10285128</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/rmattsampson/commentapi.aspx?WeblogPostID=10285128</wfw:comment><comments>http://blogs.msdn.com/b/rmattsampson/archive/2012/03/19/odata-apps-in-lightswitch.aspx#comments</comments><description>&lt;h1&gt;Oh, Data!&lt;/h1&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;&lt;span size="2"&gt;&lt;span size="2"&gt;One of the cooler features that comes with &lt;/span&gt;&lt;/span&gt;&lt;a href="http://blogs.msdn.com/b/lightswitch/archive/2012/02/29/announcing-lightswitch-in-visual-studio-11-beta.aspx" target="_blank"&gt;&lt;span size="2"&gt;&lt;span size="2"&gt;LightSwitch in Visual Studio 11 Beta&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span size="2"&gt;&lt;span size="2"&gt; is it&amp;rsquo;s support for attaching to OData Services and exposing it&amp;rsquo;s own data as an OData Service.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;OData stands for Open Data Protocol.&amp;nbsp; It&amp;rsquo;s an open protocol that defines how to expose your data for querying and updating.&amp;nbsp; This enables consumers (like LightSwitch) to connect to an OData service like it would with other data sources, for example SQL.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;There&amp;rsquo;s more and more places out there exposing their data through an OData service (see some at &lt;/span&gt;&lt;a href="http://odata.org/producers"&gt;&lt;span size="2"&gt;http://odata.org/producers&lt;/span&gt;&lt;/a&gt;&lt;span size="2"&gt;).&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;One of the slickest ones that I have found is the &lt;/span&gt;&lt;a href="http://www.commuterapi.com/" target="_blank"&gt;&lt;span size="2"&gt;Public Transit Data Community&lt;/span&gt;&lt;/a&gt;&lt;span size="2"&gt; (PTDC) service.&amp;nbsp; This OData feed is combining all the different public transit data feeds from around the United States and exposing them through one well defined OData feed.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;The PTDC has made some nice progress so far and is exposing transit information for over a dozen different agencies.&amp;nbsp; I&amp;rsquo;ve got a favorite agency on this list and that would be the Washington DC Metro agency or &amp;lsquo;WMATA&amp;rsquo; for short.&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;If you&amp;rsquo;ve ridden the DC metro (or any subway system) more than a couple times you&amp;rsquo;ve probably found yourself wondering a few things like:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style="width: 610px;" border="0" cellspacing="0" cellpadding="2"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" width="190"&gt;&lt;strong&gt;1) Where is my metro stop?&lt;/strong&gt;&lt;/td&gt;
&lt;td valign="top" width="10"&gt;&lt;img src="http://www.fromsingletomarried.com/wp-content/uploads/2008/12/metro-sign.jpg" width="153" height="229" /&gt;&lt;/td&gt;
&lt;td valign="top" width="227"&gt;
&lt;p&gt;&amp;nbsp;&lt;strong&gt;2) When is my train arriving?&lt;/strong&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="181"&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65/8475.Arrival.png" width="203" height="190" /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="190"&gt;&lt;strong&gt;3) How the heck do I get there?&lt;/strong&gt;&lt;/td&gt;
&lt;td valign="top" width="10"&gt;&lt;img src="http://dcguide.com/wp-content/uploads/2010/05/metromap.gif" width="205" height="194" /&gt;&lt;/td&gt;
&lt;td valign="top" width="227"&gt;
&lt;p&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;strong&gt;&lt;span style="font-size: x-small;" size="2"&gt;4) My personal favorite &amp;ndash; how many escalators will be broken today?&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="181"&gt;&lt;img src="http://farm4.staticflickr.com/3064/2742892300_c1a4991dc1_z.jpg?zz=1" width="166" height="221" /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="190"&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign="top" width="10"&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign="top" width="227"&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign="top" width="181"&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="190"&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign="top" width="10"&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign="top" width="227"&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign="top" width="181"&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;br /&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;&lt;span size="2"&gt;&lt;span size="2"&gt;We can figure all this out by making a LightSwitch app that consumes &lt;/span&gt;&lt;/span&gt;&lt;a href="http://transit.cloudapp.net/DevTransitODataService.svc/" target="_blank"&gt;&lt;span size="2"&gt;&lt;span size="2"&gt;this OData Service&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span size="2"&gt;&lt;span size="2"&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;&lt;span size="2"&gt;&lt;span size="2"&gt;We&amp;rsquo;ll keep it simple for this blog post, and then expand on some features over a couple more blog posts.&amp;nbsp; Here&amp;rsquo;s the rundown of what we are going to accomplish in this blog post (we&amp;rsquo;ll add some more functionality in the next post):&lt;/span&gt;&lt;/span&gt;&lt;span size="2"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Consume a popular real-time public OData feed&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Create custom queries to limit the data to just DC Metro&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Create computed properties that query a cached entity set&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Use the new Web Address data type&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;Attach To It&lt;/span&gt;&lt;/h1&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;For those of you familiar with LightSwitch V1, you&amp;rsquo;ll find that consuming OData with LightSwitch is just as easy as if you were consuming a SQL database. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Let&amp;rsquo;s get started walking through the creation of our simple app to simplify our life on the DC Metro.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Open up Visual Studio 11 Beta&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Create a new project and select LightSwitch Application (Visual C#)&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Call the app &amp;ldquo;MyDCApp&amp;rdquo;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;We should see a screen something like this now:&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/6567.image_5F00_2E7418F2.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/8105.image_5F00_thumb_5F00_5B1CD2CB.png" width="305" height="207" /&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;Click on &amp;ldquo;Attach to external Data Source&amp;rdquo; and you will see this:&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/5852.image_5F00_7E69C770.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/5556.image_5F00_thumb_5F00_1DAC6E44.png" width="309" height="243" /&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Click &amp;ldquo;Next&amp;rdquo;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;&lt;span size="2"&gt;&lt;span size="2"&gt;Use the url: &lt;/span&gt;&lt;/span&gt;&lt;a title="http://transit.cloudapp.net/DevTransitODataService.svc" href="http://transit.cloudapp.net/DevTransitODataService.svc"&gt;&lt;span size="2"&gt;&lt;span size="2"&gt;http://transit.cloudapp.net/DevTransitODataService.svc&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Select &amp;ldquo;None&amp;rdquo; for the authorization method&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Click &amp;ldquo;Next&amp;rdquo;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Import the following entities for now: Agencies, Arrivals, Entrances, Incidents, Regions, Routes, Stops, and Vehicles&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Select &amp;ldquo;Finish&amp;rdquo;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;We should have something like this now (minus the screens which we add later):&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/3806.image_5F00_03D83815.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/8015.image_5F00_thumb_5F00_57BB3B23.png" width="408" height="230" /&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Open up the Routes entity designer&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Change the KML propery from a &amp;ldquo;String&amp;rdquo; type to a &amp;ldquo;Web Address&amp;rdquo; type.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;This is a new type in LightSwitch and since the KML property is really a web address it makes sense to use it here&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Change the &amp;ldquo;Summary Property&amp;rdquo; value to RouteName&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Open up the Stops entity&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Change the &amp;ldquo;Summary Property&amp;rdquo; value to Name&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;
&lt;h1&gt;Create Some Queries&lt;/h1&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;We need to limit the data that we get back to be specific to the DC Metro for the purpose of our app. To do that we can create some queries based off the entities to limit it to just the DC Metro agency.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Right click on the Arrivals entity and select &amp;ldquo;Add Query&amp;rdquo;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Call the query MetroByArrivalTime&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Add two filters on the query, both filters will compare against a &amp;ldquo;Literal&amp;rdquo;:&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;RouteType=Metro&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;AgencyAbbreviation=WMATA&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Add a sort: ArrivalTime=Ascending&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Add a query on Routes entity, call it RoutesDCMetro. &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Add two filters on the query, both filters will compare against a &amp;ldquo;Literal&amp;rdquo;:&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;RouteType=Metro&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;AgencyAbbreviation=WMATA&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Add a query on Stops entity, call it StopsDCMetro&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Add one filter on the query, the filter will compare against a &amp;ldquo;Literal&amp;rdquo;:&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;&lt;ol&gt;&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Type=Metro&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;You should have three queries now, one each under entities: Arrivals, Routes, and Stops.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Each query makes sure that we only get data for the DC Metro system. Additionally the Arrivals query makes sure that we get the data returned to us in order of their arrival time with the &amp;ldquo;arriving&amp;rdquo; trains coming back first.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Add Computed Properties&lt;/h1&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;The Routes entity has a FinalStop0Id and a FinalStop1Id.&amp;nbsp; These two properties represent the two different ending &amp;ldquo;Stops&amp;rdquo; of the Metro route.&amp;nbsp; These aren&amp;rsquo;t very intuitive when viewed on a screen and we need to clean these up a little bit to give them a proper readable name.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;We&amp;rsquo;ll add some computed properties now to accomplish this.&amp;nbsp; Add two properties to this entity called FinalStop0Name and FinalStop1Name.&amp;nbsp; After this is done, right click the table entity &amp;ldquo;Routes&amp;rdquo; and select View Table Code.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div style="margin: 0px; padding: 0px; float: none; display: inline;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5796c4b3-e6a2-4105-9ada-aadaca723c07" class="wlWriterSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"&gt;
&lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px;"&gt;Code Snippet&lt;/div&gt;
&lt;div style="background: #ddd; max-height: 300px; overflow: auto;"&gt;&lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;" start="1"&gt;
&lt;li&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;private&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;static&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;Dictionary&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;string&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;, &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;string&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;&amp;gt; cachedFinalStops;&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;public&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;static&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;Dictionary&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;string&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;, &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;string&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;&amp;gt; GetCachedFinalStops(&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;DataWorkspace&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; myDataWorkspace)&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;{&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; (cachedFinalStops == &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;null&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;{&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;cachedFinalStops = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;new&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;Dictionary&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;string&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;, &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;string&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;&amp;gt;();&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;IEnumerable&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;c_Stop&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;&amp;gt; myStops = myDataWorkspace.TransitDataData.StopsDCMetro().Execute();&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;foreach&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; (&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;c_Stop&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; myStop &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;in&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; myStops)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;{&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;cachedFinalStops.Add(myStop.StopId, myStop.Name);&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;}&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;}&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;return&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; cachedFinalStops;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;}&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;partial&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;void&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; FinalStop1Name_Compute(&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;ref&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;string&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; result)&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;{&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;Dictionary&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;string&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;, &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;string&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;&amp;gt; cachedStops = GetCachedFinalStops(&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;this&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;.DataWorkspace);&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;result = cachedStops[&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;this&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;.FinalStop1Id];&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;}&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;partial&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;void&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; FinalStop0Name_Compute(&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;ref&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;string&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; result)&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;{&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;Dictionary&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;string&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;, &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;string&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;&amp;gt; cachedStops = GetCachedFinalStops(&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;this&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;.DataWorkspace);&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;result = cachedStops[&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;this&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;.FinalStop0Id];&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;}&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;There&amp;rsquo;s a couple things going on here.&amp;nbsp; The FinalStopName_Compute methods find the Route&amp;rsquo;s two different stop&amp;rsquo;s name instead of just using the Id.&amp;nbsp; They do this by using a LINQ query which says: For some variable q, find me all the stops on the Stops entity that have the same Id value as this Route&amp;rsquo;s stop. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;The only trick here is that we cached all of the stops on the Stops entity the first time that we launched our screen.&amp;nbsp; We do this because Metro Stops don&amp;rsquo;t ever change their names. So we can safely cache this information and then our Compute methods can query against the cached list of Stops which will speed things up a bit. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;I want to stress here though that this method of caching is really ONLY appropriate for "static" data.&amp;nbsp; That is data that we know won't be changing.&amp;nbsp; I felt comfortable caching the names of the Metro Stops as I said, because that really is data that won't change.&amp;nbsp; But you obviously would NOT want to cache, for example, the "Arrivals" entity this way because that data is definitely not static and using this method would result in you having old data in your cache.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;You should have a Routes entity that looks something like this:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/5025.image_5F00_0FF9B23C.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/4848.image_5F00_thumb_5F00_3A65E359.png" width="499" height="274" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Create Some Screens&lt;/h1&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Let&amp;rsquo;s create some screens around the queries that we made now. &lt;br /&gt;These screens will be read only, because the OData service we are querying against is read only.&amp;nbsp; So we will want to remove our insert, edit, and delete buttons.&amp;nbsp; Also, we&amp;rsquo;ll clean up our screens a bit to remove some useless data.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Create a List and Details screen for the MetroByArrivalTime query.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;&lt;span size="2"&gt;&lt;span size="2"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span size="2"&gt;&lt;span size="2"&gt;Change the &amp;ldquo;Summary&amp;rdquo; List to be a Columns Layout with the following fields:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Arrival Time, Status, Route Name, and Stop Name&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Delete the Add, Edit, and Delete buttons under the command bar since we won&amp;rsquo;t need them&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;You can customize the &amp;ldquo;Details&amp;rdquo; portion of the screen however you like, but below is what mine ended up looking like:&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/1018.image_5F00_52D07538.png"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/3678.image_5F00_156010B1.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/5100.image_5F00_thumb_5F00_7F32078D.png" width="186" height="303" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Create a List and Details screen for the RoutesDCMetro query and for the StopsDCMetro query&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Delete the Add, Edit, and Delete buttons under the command bar since we won&amp;rsquo;t need them&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;You can customize the screens however you like, my RoutesDCMetro and StopsDCMetro screens are displayed below respectively:&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/3343.image_5F00_4C620119.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/3056.image_5F00_thumb_5F00_24BB84EF.png" width="224" height="244" /&gt;&lt;/a&gt; &lt;span style="font-size: x-small;" size="2"&gt;- &lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;Note how the &amp;ldquo;Routes&amp;rdquo; screen has the Kml property set to &amp;ldquo;Web Link&amp;rdquo; for the data type&amp;rdquo;- RoutesDCMetro&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/4024.image_5F00_75F5CC4C.png"&gt;&lt;img style="margin: 0px; display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/0880.image_5F00_thumb_5F00_112E254E.png" width="213" height="244" /&gt;&lt;/a&gt;&lt;span style="font-size: x-small;" size="2"&gt; -&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt; StopsDCMetro&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h1&gt;&lt;/h1&gt;
&lt;h1&gt;Run It&lt;/h1&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;Hit F5 now in Visual Studio to run it and check out some of the features of the application and what LightSwitch provides.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;The Metro By Arrival Time screen shows us the arriving metro trains, how many cars are arriving, what the status is (BRD for Boarding or ARR for Arriving), and what the destination stop is.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/3441.image_5F00_496C9C66.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/2364.image_5F00_thumb_5F00_01AB137F.png" width="496" height="246" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;&lt;span size="2"&gt;The Routes screen has the stop information for each route, as well as a clickable map of the route. If you click on the &lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/Keyhole_Markup_Language" target="_blank"&gt;&lt;span size="2"&gt;Kml&lt;/span&gt;&lt;/a&gt;&lt;span size="2"&gt; link it will open up in an application like Google Earth and provide an overview of the route (see below).&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/0383.image_5F00_67D6DD4F.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/4812.image_5F00_thumb_5F00_40306125.png" width="514" height="146" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;KML Link:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/4578.image_5F00_2D7B676E.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/0336.image_5F00_thumb_5F00_0B435BE8.png" width="376" height="161" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And lastly the Stops DC Metro screen displays the location and name of each stop.&lt;/p&gt;
&lt;h1&gt;Concluding Part 1&lt;/h1&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;To summarize what we&amp;rsquo;ve covered up to this point - we gave a basic example of how Visual Studio Light Switch can attach to a public OData feed. We showed the new web address data type.&amp;nbsp; We utilized computed fields with caching to improve our performance.&amp;nbsp; And we used queries to narrow down our data.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;We still have a few problems we need to get to in the next blog post.&amp;nbsp; We will customize the Stops screen so that it can provide us with a map of the Stops location instead of just latitude and longitude coordinates.&amp;nbsp; The Incidents data contains all the information we want regarding broken escalators, so we will need to hook that up too so that we can retrieve that information for each given stop.&amp;nbsp; Also, since this data is done in &amp;ldquo;real time&amp;rdquo; it&amp;rsquo;d be nice to add some automatic refresh to our application so that our data we are viewing doesn&amp;rsquo;t get too stale.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;" size="2"&gt;&lt;span size="2"&gt;I&amp;rsquo;ll be looking to update the blog again sometime next week, until then feel free to leave any comments or questions and I&amp;rsquo;ll do my best to get back to them.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;span style="font-family: arial,helvetica,sans-serif; font-size: small;"&gt;Thanks a lot, Cheers -&lt;/span&gt; &lt;img class="wlEmoticon wlEmoticon-martiniglass" alt="Martini glass" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/3005.wlEmoticon_2D00_martiniglass_5F00_2E241D98.png" /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;span style="font-size: x-small;" size="2"&gt;CODE IS UPLOADED&amp;nbsp;NOW FOR&amp;nbsp;VB.NET&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;a href="http://digg.com/submit?url=http%3a%2f%2fblogs.msdn.com%2fb%2frmattsampson%2farchive%2f2012%2f03%2f19%2fodata-apps-in-lightswitch.aspx&amp;amp;title=OData+Apps+In+LightSwitch%2c+Part+1"&gt;&lt;img style="border: 0px currentColor;" title="Digg This" border="0" alt="Digg This" src="http://digg.com/img/badges/100x20-digg-button.png" width="100" height="20" /&gt;&lt;/a&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65/8475.Arrival.png"&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10285128" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-28-51-28/MyDCAppVB.zip" length="52043516" type="application/octet-stream" /><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/LightSwitch/">LightSwitch</category><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/OData/">OData</category><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/Visual+Studio+11+Beta/">Visual Studio 11 Beta</category></item><item><title>How Do I: Import and Store a Data File</title><link>http://blogs.msdn.com/b/rmattsampson/archive/2011/05/23/how-to-import-and-store-a-data-file.aspx</link><pubDate>Mon, 23 May 2011 17:47:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10167431</guid><dc:creator>Matt Sampson</dc:creator><slash:comments>30</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/rmattsampson/rsscomments.aspx?WeblogPostID=10167431</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/rmattsampson/commentapi.aspx?WeblogPostID=10167431</wfw:comment><comments>http://blogs.msdn.com/b/rmattsampson/archive/2011/05/23/how-to-import-and-store-a-data-file.aspx#comments</comments><description>&lt;p&gt;Today&amp;rsquo;s post is going to be a short one about how to import a file through a Visual Studio LightSwitch application (Desktop or Web) and store the data on the backend (e.g. SQL Server).&lt;/p&gt;
&lt;p&gt;Sometimes we want to upload files in binary format and store them in the database, like a Word document or PDF file or any other file containing unstructured data. LightSwitch already has the built-in ability to store and retrieve images, but if you want to store other types of files we have to write a small bit of code. &lt;/p&gt;
&lt;h3&gt;Backstory&lt;/h3&gt;
&lt;p&gt;This post is really just me picking out various pieces of code from my other posts and cramming it together to make a new post.&amp;nbsp; Which is a nice break for me, since writing a post often takes about a week (after I write the code and write up a draft blog, then get feedback, and double check the code several times).&amp;nbsp; But with this one I should be done in a day leaving more time to enjoy the very brief Summers we have up here in Fargo, North Dakota.&lt;/p&gt;
&lt;h3&gt;Create the project and a table&lt;/h3&gt;
&lt;p&gt;Alright, let&amp;rsquo;s get started making a simple LightSwitch Web Application. &lt;br /&gt;Let&amp;rsquo;s create the project, and a table that will hold our file data.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Launch Visual Studio LightSwitch and create a new C# Visual Studio LightSwitch project &lt;/li&gt;
&lt;li&gt;Call the project: ImportFiles &lt;/li&gt;
&lt;li&gt;In the Solution Explorer, right click &amp;ldquo;Properties&amp;rdquo; and select Open. &lt;/li&gt;
&lt;li&gt;Change the Application Type from &amp;ldquo;Desktop&amp;rdquo; to &amp;ldquo;Web&amp;rdquo; &lt;ol&gt;
&lt;li&gt;Note - this sample will work as a Desktop application as well &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;Add a table called &amp;ldquo;FileInformation&amp;rdquo; and add the following fields to the table: &lt;ol&gt;
&lt;li&gt;Name | String | &lt;/li&gt;
&lt;li&gt;Miscellaneous | String | &lt;/li&gt;
&lt;li&gt;Data | Binary | &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;You should have a table now that looks like this: &lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/7762.image_5F00_38A37C68.png"&gt;&lt;img height="179" width="544" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/3157.image_5F00_thumb_5F00_749F9850.png" alt="image" border="0" title="image" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" /&gt;&lt;/a&gt; &lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;&lt;/h3&gt;
&lt;h3&gt;Create the screen &lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Add a screen using the &amp;ldquo;Editable Grid Screen&amp;rdquo; template and tie the screen to the FileInformation table. &lt;/li&gt;
&lt;li&gt;In the screen designer, under Rows Layout &amp;ndash;&amp;gt; Data Grid &amp;ndash;&amp;gt; Data Grid Row delete the &amp;ldquo;Data&amp;rdquo; control so that it won&amp;rsquo;t display when we run the application &lt;ol&gt;
&lt;li&gt;It doesn&amp;rsquo;t make much sense for us to display this field on the screen since it just the file&amp;rsquo;s binary data. &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;In the screen designer, under Rows Layout &amp;ndash;&amp;gt; Screen Command Bar, add&amp;nbsp; a button called &amp;ldquo;ImportAFile&amp;rdquo; &lt;/li&gt;
&lt;li&gt;You should now have a screen that looks something like this: &lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/6710.image_5F00_7784D736.png"&gt;&lt;img height="289" width="542" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/2821.image_5F00_thumb_5F00_29D884E9.png" alt="image" border="0" title="image" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" /&gt;&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;Right click the ImportAFile button and select &amp;ldquo;Edit Execute Code&amp;rdquo; &lt;ol&gt;
&lt;li&gt;We do this to create the &amp;ldquo;User&amp;rdquo; folder where we will be placing some custom user code.&amp;nbsp; We&amp;rsquo;ll come back and add our button code later &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;&lt;/h3&gt;
&lt;h3&gt;&lt;/h3&gt;
&lt;h3&gt;&lt;/h3&gt;
&lt;h3&gt;Add a custom Silverlight dialog&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;In the Solution Explorer we need to switch to the &amp;ldquo;File View&amp;rdquo; mode so we can add some custom code. &lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/7120.image_5F00_7D1FA542.png"&gt;&lt;img height="178" width="226" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/3857.image_5F00_thumb_5F00_78E5A7B0.png" alt="image" border="0" title="image" style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" /&gt;&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;After switching to the File View mode, navigate to the Client project and open up the User Code folder &lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/8233.image_5F00_7367113F.png"&gt;&lt;img height="132" width="150" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/5100.image_5F00_thumb_5F00_16675CE3.png" alt="image" border="0" title="image" style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" /&gt;&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;We are going to add our custom Silverlight dialog just like we did in the &lt;a target="_blank" href="http://blogs.msdn.com/b/rmattsampson/archive/2011/05/10/how-do-i-import-data-from-a-web-application.aspx"&gt;last blog post&lt;/a&gt;.&amp;nbsp; We need our own custom Silverlight dialog because we want to display an &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/system.windows.controls.openfiledialog(VS.95).aspx"&gt;OpenFileDialog&lt;/a&gt; to the user and we are running inside a LightSwitch web application. (For the longer explanation please read my &lt;a target="_blank" href="http://blogs.msdn.com/b/rmattsampson/archive/2011/05/10/how-do-i-import-data-from-a-web-application.aspx"&gt;previous blog post&lt;/a&gt;). &lt;/li&gt;
&lt;li&gt;Right click UserCode folder and select &amp;ldquo;Add-&amp;gt; New Item&amp;rdquo; &lt;/li&gt;
&lt;li&gt;Select &amp;ldquo;Text File&amp;rdquo; in the &amp;ldquo;Add New Item&amp;rdquo; dialog.&amp;nbsp; Call the file &amp;ldquo;SelectFileWindow.xaml&amp;rdquo; &lt;/li&gt;
&lt;li&gt;Now copy and paste the below code into the &amp;ldquo;SelectFileWindow.xaml&amp;rdquo; file:
&lt;pre style="background-color: #fbfbfb; min-height: 40px; width: 541px; height: 379px; overflow: auto; border: #cecece 1px solid; padding: 5px;"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #c71585;"&gt;controls&lt;/span&gt;:&lt;span style="color: #800000;"&gt;ChildWindow&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;x&lt;/span&gt;:&lt;span style="color: #ff0000;"&gt;Class&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"LightSwitchApplication.UserCode.SelectFileWindow"&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;           &lt;span style="color: #ff0000;"&gt;xmlns&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt; 
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;           &lt;span style="color: #ff0000;"&gt;xmlns&lt;/span&gt;:&lt;span style="color: #ff0000;"&gt;x&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt; 
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;           &lt;span style="color: #ff0000;"&gt;xmlns&lt;/span&gt;:&lt;span style="color: #ff0000;"&gt;controls&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;           &lt;span style="color: #ff0000;"&gt;Width&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"394"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Height&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"305"&lt;/span&gt; 
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;           &lt;span style="color: #ff0000;"&gt;Title&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"Select File Dialog"&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    &lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;Grid&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;x&lt;/span&gt;:&lt;span style="color: #ff0000;"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"LayoutRoot"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Margin&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"2"&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;RowDefinition&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;RowDefinition&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Height&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"Auto"&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;Button&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;x&lt;/span&gt;:&lt;span style="color: #ff0000;"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"CancelButton"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Content&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"Cancel"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Click&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"CancelButton_Click"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Width&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"75"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Height&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"23"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;HorizontalAlignment&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"Right"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Margin&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"0,12,0,0"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Grid&lt;/span&gt;.&lt;span style="color: #ff0000;"&gt;Row&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"1"&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;Button&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;x&lt;/span&gt;:&lt;span style="color: #ff0000;"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"OKButton"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Content&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"OK"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Click&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"OKButton_Click"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Width&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"75"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Height&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"23"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;HorizontalAlignment&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"Right"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Margin&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"0,12,79,0"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Grid&lt;/span&gt;.&lt;span style="color: #ff0000;"&gt;Row&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"1"&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;Button&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Content&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"Browse"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Height&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"23"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;HorizontalAlignment&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"Left"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Margin&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"291,92,0,0"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"BrowseButton"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;VerticalAlignment&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"Top"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Width&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"75"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Click&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"BrowseButton_Click"&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;TextBox&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Height&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"23"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;HorizontalAlignment&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"Left"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Margin&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"66,92,0,0"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"FileTextBox"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;VerticalAlignment&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"Top"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Width&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"219"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;IsEnabled&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"True"&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    &lt;span style="color: #0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;Grid&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #c71585;"&gt;controls&lt;/span&gt;:&lt;span style="color: #800000;"&gt;ChildWindow&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;This Silverlight dialog code contains 4 controls &amp;ndash; an OK button, Cancel button, Text field, and a Browse button.&amp;nbsp; The Browse button will launch an OpenFileDialog dialog which will let the user select a file to import, and the text field will display the name of the file about to be imported. &lt;/li&gt;
&lt;li&gt;We need to add some code for our Silverlight dialog, so right click the &amp;ldquo;UserCode&amp;rdquo; folder and select &amp;ldquo;Add-&amp;gt; Class&amp;rdquo; &lt;/li&gt;
&lt;li&gt;Name the class &amp;ldquo;SelectFileWindow.cs&amp;rdquo; and copy the below code into the class:
&lt;pre style="background-color: #fbfbfb; min-height: 40px; width: 542px; height: 460px; overflow: auto; border: #cecece 1px solid; padding: 5px;"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #008000;"&gt;//' Copyright &amp;copy; Microsoft Corporation.  All Rights Reserved.&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #008000;"&gt;//' This code released under the terms of the &lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #008000;"&gt;//' Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; System;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; System.IO;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; System.Windows;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; System.Windows.Controls;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;namespace&lt;/span&gt; LightSwitchApplication.UserCode
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;{
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; partial &lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; SelectFileWindow : ChildWindow
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; SelectFileWindow()
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            InitializeComponent();
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;private&lt;/span&gt; FileStream documentStream;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; FileStream DocumentStream
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff;"&gt;get&lt;/span&gt; { &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; documentStream; }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff;"&gt;set&lt;/span&gt; { documentStream = &lt;span style="color: #0000ff;"&gt;value&lt;/span&gt;; }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;private&lt;/span&gt; String safeFileName;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; String SafeFileName
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff;"&gt;get&lt;/span&gt; { &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; safeFileName; }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff;"&gt;set&lt;/span&gt; { safeFileName = &lt;span style="color: #0000ff;"&gt;value&lt;/span&gt;; }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// OK Button&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; OKButton_Click(&lt;span style="color: #0000ff;"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.DialogResult = &lt;span style="color: #0000ff;"&gt;true&lt;/span&gt;;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// Cancel button&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; CancelButton_Click(&lt;span style="color: #0000ff;"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.DialogResult = &lt;span style="color: #0000ff;"&gt;false&lt;/span&gt;;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// Browse button&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; BrowseButton_Click(&lt;span style="color: #0000ff;"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            OpenFileDialog openFileDialog = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; OpenFileDialog();
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (openFileDialog.ShowDialog() == &lt;span style="color: #0000ff;"&gt;true&lt;/span&gt;)
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.FileTextBox.Text = openFileDialog.File.Name;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.safeFileName = openFileDialog.File.Name;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.FileTextBox.IsReadOnly = &lt;span style="color: #0000ff;"&gt;true&lt;/span&gt;;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                FileStream myStream = openFileDialog.File.OpenRead();
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.documentStream = myStream;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;}
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;The SelectFileWindow class contains the following code: &lt;ol&gt;
&lt;li&gt;The methods for our button controls &lt;/li&gt;
&lt;li&gt;The browse button has code in it to create a System.Windows.Controls.OpenFileDialog object which we use to open up our Open File Dialog to allow the user to pick any arbitrary file to import. &lt;/li&gt;
&lt;li&gt;A public FileStream property which will contain the data for the file we want to import &lt;/li&gt;
&lt;li&gt;A public String property which will contain the name of the file we want to import &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;We need to add a reference to the Silverlight dll we are using, so in Solution Explorer, navigate to &amp;ldquo;Client &amp;ndash;&amp;gt; References&amp;rdquo;, right click and select &amp;ldquo;Add Reference&amp;hellip;&amp;rdquo; &lt;/li&gt;
&lt;li&gt;Add a .NET reference to the System.Windows.Controls assembly &lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;Add our screen&amp;rsquo;s button code&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Let&amp;rsquo;s switch back to the &amp;ldquo;Logical View&amp;rdquo; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/3365.image_5F00_71A61F9E.png"&gt;&lt;img height="100" width="244" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/6014.image_5F00_thumb_5F00_352DAAF4.png" alt="image" border="0" title="image" style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" /&gt;&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;Open up the screen designer for the EditableFileInformationsGrid &lt;/li&gt;
&lt;li&gt;Right click the &amp;ldquo;ImportAFile&amp;rdquo; and select &amp;ldquo;Edit Execute Code&amp;rdquo; &lt;/li&gt;
&lt;li&gt;Copy and paste the below code into the EditableFileInformationsGrid.cs: &lt;/li&gt;
&lt;pre style="background-color: #fbfbfb; min-height: 40px; width: 528px; height: 354px; overflow: auto; border: #cecece 1px solid; padding: 5px;"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #008000;"&gt;//' Copyright &amp;copy; Microsoft Corporation.  All Rights Reserved.&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #008000;"&gt;//' This code released under the terms of the &lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #008000;"&gt;//' Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; System;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; System.IO;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; System.IO.IsolatedStorage;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; System.Linq;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; LightSwitchApplication.UserCode;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; Microsoft.LightSwitch;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; Microsoft.LightSwitch.Framework.Client;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; Microsoft.LightSwitch.Presentation;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; Microsoft.LightSwitch.Presentation.Extensions;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; Microsoft.LightSwitch.Threading;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;namespace&lt;/span&gt; LightSwitchApplication
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;{
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; partial &lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; EditableFileInformationsGrid
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        partial &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; ImportAFile_Execute()
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #008000;"&gt;// To invoke our own dialog, we have to do this inside of the "Main" Dispatcher&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #008000;"&gt;// And, since this is a web application, we can't directly invoke the Silverlight OpenFileDialog&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #008000;"&gt;// class, we have to first invoke our own Silverlight custom control (i.e. SelectFileWindow)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #008000;"&gt;// and that control will be able to invoke the OpenFileDialog class (via the Browse button)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            Dispatchers.Main.BeginInvoke(() =&amp;gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                SelectFileWindow selectFileWindow = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; SelectFileWindow();
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                selectFileWindow.Closed += &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; EventHandler(selectFileWindow_Closed);
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                selectFileWindow.Show();
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            });
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// Invoked when our custom Silverlight window closes&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; selectFileWindow_Closed(&lt;span style="color: #0000ff;"&gt;object&lt;/span&gt; sender, EventArgs e)
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            SelectFileWindow selectFileWindow = (SelectFileWindow)sender;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #008000;"&gt;// Continue if they hit the OK button AND they selected a file&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (selectFileWindow.DialogResult == &lt;span style="color: #0000ff;"&gt;true&lt;/span&gt; &amp;amp;&amp;amp; (selectFileWindow.DocumentStream != &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;))
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #0000ff;"&gt;byte&lt;/span&gt;[] fileData = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;byte&lt;/span&gt;[selectFileWindow.DocumentStream.Length];
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; (StreamReader streamReader = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; StreamReader(selectFileWindow.DocumentStream))
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                    &lt;span style="color: #0000ff;"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; i = 0; i &amp;lt; selectFileWindow.DocumentStream.Length; i++)
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                    {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                        fileData[i] = (&lt;span style="color: #0000ff;"&gt;byte&lt;/span&gt;)selectFileWindow.DocumentStream.ReadByte();
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                    }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #008000;"&gt;// Create a new record for this file, and store the data, name and length&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                FileInformation fileInformation = &lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.DataWorkspace.ApplicationData.FileInformations.AddNew();
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                fileInformation.Name = selectFileWindow.SafeFileName;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                fileInformation.Miscellaneous = "&lt;span style="color: #8b0000;"&gt;Size of file in bytes: &lt;/span&gt;" + fileData.Length;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                fileInformation.Data = fileData;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                selectFileWindow.DocumentStream.Close();
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                selectFileWindow.DocumentStream.Dispose();
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;}
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;/pre&gt;
&lt;li&gt;There are two methods in this class: &lt;ol&gt;
&lt;li&gt;ImportAFile_Execute() &amp;ndash; since we are inside of button code here we are NOT inside the main UI thread anymore.&amp;nbsp; So we need to switch back to the main UI thread only because we want to display our own UI dialogs (like our custom Silverlight dialog and an OpenFileDialog).&amp;nbsp; This method switches to the main UI, invokes our Silverlight dialog, and adds an EventHandler to the &amp;ldquo;Closed&amp;rdquo; event.&amp;nbsp; So that when the dialog is closed, we call our own method to do some additional work. &lt;/li&gt;
&lt;li&gt;selectFileWindow_Closed() &amp;ndash; this method is invoked once our Silverlight dialog closes.&amp;nbsp; It reads in the file from the SelectFileWindow.DocumentStream public property we mentioned earlier.&amp;nbsp; And stores the data from this FileStream into a byte array.&amp;nbsp; We then create a new record for our FileInformation table, and set the Name field to the name of the file, the Miscellaneous field is set to the size of the file, and the Data field is set to the value of the byte array.&amp;nbsp; The Data field is what actually contains our imported file. &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;Run it and import some files&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;In Solution Explorer, right click the ImportFiles project, and select &amp;ldquo;Build&amp;rdquo;. &lt;/li&gt;
&lt;li&gt;After the build, press F5 to run your project &lt;/li&gt;
&lt;li&gt;You should see the inside the command bar on the screen a button called &amp;ldquo;Import A File&amp;rdquo; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/2018.image_5F00_21C264FC.png"&gt;&lt;img height="168" width="329" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/1854.image_5F00_thumb_5F00_4B75BA22.png" alt="image" border="0" title="image" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" /&gt;&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;Click the &amp;ldquo;Import A File&amp;rdquo; button to display our custom Silverlight Dialog &lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/2437.image_5F00_667E6363.png"&gt;&lt;img height="268" width="339" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/6746.image_5F00_thumb_5F00_62B098C6.png" alt="image" border="0" title="image" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" /&gt;&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;Select the &amp;ldquo;Browse&amp;rdquo; button and select any file you wish to import &lt;/li&gt;
&lt;li&gt;Click &amp;ldquo;OK&amp;rdquo; &lt;/li&gt;
&lt;li&gt;Our code to import the data will now run and we will get a new record created on our screen &lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/3857.image_5F00_100208CA.png"&gt;&lt;img height="176" width="380" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/6562.image_5F00_thumb_5F00_05ED679F.png" alt="image" border="0" title="image" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" /&gt;&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;As you can see, we display the file&amp;rsquo;s name and it&amp;rsquo;s size in bytes &lt;/li&gt;
&lt;li&gt;You can now save the data to persist it to the database by clicking the &amp;ldquo;Save&amp;rdquo; button on the command bar &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Additionally, there is an extension that can be added to Visual Studio LightSwitch called &lt;a href="http://visualstudiogallery.msdn.microsoft.com/9c0ff6c8-9523-4e5b-96c7-543107416fbe"&gt;Document Toolkit for LightSwitch&lt;/a&gt;, which handles importing and viewing Word Documents.&amp;nbsp; It will only work for Desktop applications, and it isn&amp;rsquo;t free, but other than that it looks like a slick extension.&lt;/p&gt;
&lt;p&gt;That&amp;rsquo;s it for this brief post.&amp;nbsp; I've included a zip file below of the C# code.&lt;/p&gt;
&lt;p&gt;Again, love to hear if there are any questions, and if you think something is wrong with this code (or the title) then you are probably right &lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/0211.wlEmoticon_2D00_winkingsmile_5F00_21CE76CA.png" alt="Winking smile" class="wlEmoticon wlEmoticon-winkingsmile" style="border-style: none;" /&gt; so please let me know.&lt;/p&gt;
&lt;p&gt;-Matt Sampson &lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/6574.wlEmoticon_2D00_martiniglass_5F00_585C220E.png" alt="Martini glass" class="wlEmoticon wlEmoticon-martiniglass" style="border-style: none;" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10167431" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-16-74-31/ImportFiles.zip" length="2092254" type="application/octet-stream" /><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/LightSwitch/">LightSwitch</category><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/Visual+Studio+LightSwitch/">Visual Studio LightSwitch</category><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/Web+Application/">Web Application</category></item><item><title>How Do I: Import Data While Running a LightSwitch Web Application</title><link>http://blogs.msdn.com/b/rmattsampson/archive/2011/05/10/how-do-i-import-data-from-a-web-application.aspx</link><pubDate>Tue, 10 May 2011 14:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10162939</guid><dc:creator>Matt Sampson</dc:creator><slash:comments>25</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/rmattsampson/rsscomments.aspx?WeblogPostID=10162939</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/rmattsampson/commentapi.aspx?WeblogPostID=10162939</wfw:comment><comments>http://blogs.msdn.com/b/rmattsampson/archive/2011/05/10/how-do-i-import-data-from-a-web-application.aspx#comments</comments><description>&lt;p&gt;Importing data into a Microsoft Visual Studio LightSwitch application can be a bit tricky, especially if we are talking about a LightSwitch web application.&amp;nbsp; Since I&amp;rsquo;ve heard several people ask how to import data using a web application, I figured now would be a good time to blog about this.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m going to teach you some tips and tricks on importing data into a web application. It can get tricky in this scenario because web applications typically have additional security issues you need to deal with.&amp;nbsp; But I think you&amp;rsquo;ll find once we are done, that there is very little code, and it&amp;rsquo;s easy to understand.&lt;/p&gt;
&lt;h3&gt;Overview&lt;/h3&gt;
&lt;p&gt;Some other LightSwitch people have already blogged about importing data into a LightSwitch application (e.g. &lt;a target="_blank" href="http://blogs.msdn.com/b/lightswitch/archive/2010/10/08/how-do-i-import-and-export-data-to-from-a-csv-file-dan-seefeldt.aspx"&gt;Dan Seefeldt&lt;/a&gt; and the &lt;a target="_blank" href="http://blogs.msdn.com/b/lightswitch/archive/2011/04/13/how-to-import-data-from-excel.aspx?wa=wsignin1.0"&gt;LightSwitch team&lt;/a&gt;).&amp;nbsp; These are some awesome posts for the basics of importing and exporting.&amp;nbsp; But for our slightly more specialized scenario we want to:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Create a web application &lt;/li&gt;
&lt;li&gt;Let the user select a comma separate file (e.g. *.csv) to import &lt;/li&gt;
&lt;li&gt;Populate our LightSwitch data with data from the comma separated file &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The real issue we need to work around is the fact that we have a web application and NOT a desktop application.&amp;nbsp; Because of that we are going to have to do a couple of extra steps to make this work.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s get started!&lt;/p&gt;
&lt;h3&gt;&lt;/h3&gt;
&lt;h3&gt;Create a Simple Web Application&lt;/h3&gt;
&lt;p&gt;Because I&amp;rsquo;m lazy, we are going to make another application to manage &amp;ldquo;Contacts&amp;rdquo; for this example (like we did for the &lt;a target="_blank" href="http://blogs.msdn.com/b/rmattsampson/archive/2011/04/25/how-do-i-export-data-to-a-word-labels-document.aspx"&gt;last blog post&lt;/a&gt;).&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Launch Microsoft Visual Studio LightSwitch &lt;/li&gt;
&lt;li&gt;Create a new C# Project (I&amp;rsquo;ll include some VB.NET code for VB fans at the end of this blog) &lt;/li&gt;
&lt;li&gt;Call the project &amp;ldquo;ImportDataFromAWebApp&amp;rdquo; &lt;/li&gt;
&lt;li&gt;In the Solution Explorer, right click the &amp;ldquo;Properties&amp;rdquo; icon and select &amp;ldquo;Open&amp;rdquo;: &lt;ol&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/3404.image_5F00_2323A523.png"&gt;&lt;img height="107" width="243" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/3010.image_5F00_thumb_5F00_1478F93E.png" alt="image" border="0" title="image" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" /&gt;&lt;/a&gt; &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;In the Properties window that opens, select the &amp;ldquo;Application Type&amp;rdquo; tab, and pick &amp;ldquo;Web&amp;rdquo; to switch from a Desktop application to a Web application for this project &lt;ol&gt;
&lt;li&gt;Note - Our code will also work in a Desktop application as well &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;Add the Table&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;In the Solution Explorer, right click the Data Sources node and select &amp;ldquo;Add Table&amp;rdquo; &lt;/li&gt;
&lt;li&gt;Name the table &amp;ldquo;Contact&amp;rdquo; and populate it with the following fields (formatted like [Field Name | Data Type | Required]): &lt;ol&gt;
&lt;li&gt;FirstName | String | Required &lt;/li&gt;
&lt;li&gt;MiddleName | String | &lt;/li&gt;
&lt;li&gt;LastName | String | Required &lt;/li&gt;
&lt;li&gt;AddressLine1 | String | &lt;/li&gt;
&lt;li&gt;AddressLine2 | String | &lt;/li&gt;
&lt;li&gt;City | String | &lt;/li&gt;
&lt;li&gt;State | String | &lt;/li&gt;
&lt;li&gt;ZipCode | String | &lt;/li&gt;
&lt;li&gt;Country | String | &lt;/li&gt;
&lt;li&gt;PhoneNumber1 | Phone Number | &lt;/li&gt;
&lt;li&gt;PhoneNumber2 | Phone Number | &lt;/li&gt;
&lt;li&gt;BirthDate | Date | &lt;/li&gt;
&lt;li&gt;MiscellaneousInformation | String | &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;The table should look something like this when we are done: &lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/0777.image_5F00_4C2CD01F.png"&gt;&lt;img height="309" width="557" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/4555.image_5F00_thumb_5F00_046B4738.png" alt="image" border="0" title="image" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" /&gt;&lt;/a&gt; &lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;Add the Screen&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;In the Solution Explorer, right click the Screens node and select &amp;ldquo;Add Screen&amp;hellip;&amp;rdquo; &lt;/li&gt;
&lt;li&gt;Pick the &amp;ldquo;Editable Grid Screen&amp;rdquo; template &lt;/li&gt;
&lt;li&gt;For the Screen Data &amp;ndash; select the table we just created &amp;ldquo;Contact&amp;rdquo; &lt;/li&gt;
&lt;li&gt;Accept the defaulted screen name (should be &amp;ldquo;EditableContactsGrid&amp;rdquo;) &lt;/li&gt;
&lt;li&gt;Click &amp;ldquo;OK&amp;rdquo; &lt;/li&gt;
&lt;li&gt;In the Screen Designer, navigate to &amp;ldquo;Rows Layout &amp;ndash;&amp;gt; Data Grid &amp;ndash;&amp;gt; Command Bar&amp;rdquo; and add a button under the Command Bar. &lt;/li&gt;
&lt;li&gt;Call the button method name &amp;ldquo;ImportData&amp;rdquo; &lt;/li&gt;
&lt;li&gt;You should now have a screen that looks something like this: &lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/1447.image_5F00_5611C18A.png"&gt;&lt;img height="467" width="473" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/7612.image_5F00_thumb_5F00_6A971108.png" alt="image" border="0" title="image" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" /&gt;&lt;/a&gt;&amp;nbsp; &lt;/li&gt;
&lt;li&gt;Right click the &amp;ldquo;Import Data&amp;rdquo; button and select &amp;ldquo;Edit Execute Code&amp;rdquo; to generate the button method stub &lt;ol&gt;
&lt;li&gt;Doing this will generate the &amp;ldquo;User Code&amp;rdquo; folder for us that we&amp;rsquo;d like to have for our next steps.&amp;nbsp; &lt;/li&gt;
&lt;li&gt;We&amp;rsquo;ll add code to this button method later on. &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;Add a Simple Silverlight dialog&lt;/h3&gt;
&lt;p&gt;Now comes the unusual part of this example.&amp;nbsp; We are going to add our own Silverlight dialog to our LightSwitch application.&amp;nbsp; The &amp;ldquo;Import Data&amp;rdquo; button is going to invoke this Silverlight dialog. (I am not the first to go adding Silverlight dialogs to a LightSwitch application &amp;ndash; see &lt;a target="_blank" href="http://blogs.msdn.com/b/lightswitch/archive/2011/04/08/how-do-i-display-a-chart-built-on-aggregated-data-eric-erhardt.aspx"&gt;Eric Erhardt&amp;rsquo;s blog post on this&lt;/a&gt;.)&lt;/p&gt;
&lt;p&gt;I used Visual Studio Ultimate to make my own very simple Silverlight dialog which we are going to import into our Visual Studio LightSwitch project.&amp;nbsp; The Silverlight dialog contains 4 controls:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;A &amp;ldquo;Browse&amp;rdquo; button which will open up a &amp;ldquo;OpenFileDialog&amp;rdquo; window and allow the user to select a .csv file &lt;/li&gt;
&lt;li&gt;An &amp;ldquo;OK&amp;rdquo; button to accept the file you selected &lt;/li&gt;
&lt;li&gt;A &amp;ldquo;Cancel&amp;rdquo; button to abort &lt;/li&gt;
&lt;li&gt;And a text control that displays the name of the file you selected &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Let&amp;rsquo;s add the dialog now, and then I&amp;rsquo;ll give the technical reasons for why we are doing it this way.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;In Solution Explorer, click the drop down arrow on the &amp;ldquo;Logical View&amp;rdquo; button and select &amp;ldquo;File View&amp;rdquo; &lt;ol&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/6622.image_5F00_70DDE796.png"&gt;&lt;img height="179" width="225" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/1447.image_5F00_thumb_5F00_108CC15F.png" alt="image" border="0" title="image" style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" /&gt;&lt;/a&gt; &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;In Solution Explorer, navigate to &amp;ldquo;Client &amp;ndash;&amp;gt; UserCode&amp;rdquo; &lt;/li&gt;
&lt;li&gt;Right click the &amp;ldquo;UserCode&amp;rdquo; folder and select &amp;ldquo;Add &amp;ndash;&amp;gt; New Item&amp;hellip;&amp;rdquo; &lt;ol&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/6131.image_5F00_49376B6C.png"&gt;&lt;img height="257" width="319" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/4555.image_5F00_thumb_5F00_53F4C2C1.png" alt="image" border="0" title="image" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" /&gt;&lt;/a&gt; &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;Select&amp;nbsp; &amp;ldquo;Text File&amp;rdquo; in the &amp;ldquo;Add New Item&amp;rdquo; dialog.&amp;nbsp; Call the file &amp;ldquo;SelectFileWindow.xaml&amp;rdquo;. &lt;/li&gt;
&lt;li&gt;Now copy and paste the below code into the &amp;ldquo;SelectFileWindow.xaml&amp;rdquo; file (you may need to open up the .xaml file with Notepad to add this code):
&lt;pre style="background-color: #fbfbfb; min-height: 40px; width: 577px; height: 327px; overflow: auto; border: #cecece 1px solid; padding: 5px;"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #c71585;"&gt;controls&lt;/span&gt;:&lt;span style="color: #800000;"&gt;ChildWindow&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;x&lt;/span&gt;:&lt;span style="color: #ff0000;"&gt;Class&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"LightSwitchApplication.UserCode.SelectFileWindow"&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;           &lt;span style="color: #ff0000;"&gt;xmlns&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt; 
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;           &lt;span style="color: #ff0000;"&gt;xmlns&lt;/span&gt;:&lt;span style="color: #ff0000;"&gt;x&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt; 
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;           &lt;span style="color: #ff0000;"&gt;xmlns&lt;/span&gt;:&lt;span style="color: #ff0000;"&gt;controls&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;           &lt;span style="color: #ff0000;"&gt;Width&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"394"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Height&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"305"&lt;/span&gt; 
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;           &lt;span style="color: #ff0000;"&gt;Title&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"Select File Dialog"&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    &lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;Grid&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;x&lt;/span&gt;:&lt;span style="color: #ff0000;"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"LayoutRoot"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Margin&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"2"&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;RowDefinition&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;RowDefinition&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Height&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"Auto"&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;Button&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;x&lt;/span&gt;:&lt;span style="color: #ff0000;"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"CancelButton"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Content&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"Cancel"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Click&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"CancelButton_Click"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Width&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"75"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Height&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"23"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;HorizontalAlignment&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"Right"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Margin&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"0,12,0,0"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Grid&lt;/span&gt;.&lt;span style="color: #ff0000;"&gt;Row&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"1"&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;Button&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;x&lt;/span&gt;:&lt;span style="color: #ff0000;"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"OKButton"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Content&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"OK"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Click&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"OKButton_Click"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Width&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"75"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Height&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"23"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;HorizontalAlignment&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"Right"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Margin&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"0,12,79,0"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Grid&lt;/span&gt;.&lt;span style="color: #ff0000;"&gt;Row&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"1"&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;Button&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Content&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"Browse"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Height&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"23"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;HorizontalAlignment&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"Left"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Margin&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"291,92,0,0"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"BrowseButton"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;VerticalAlignment&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"Top"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Width&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"75"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Click&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"BrowseButton_Click"&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;TextBox&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Height&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"23"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;HorizontalAlignment&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"Left"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Margin&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"66,92,0,0"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"FileTextBox"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;VerticalAlignment&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"Top"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;Width&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"219"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;IsEnabled&lt;/span&gt;=&lt;span style="color: #0000ff;"&gt;"True"&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    &lt;span style="color: #0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;Grid&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #c71585;"&gt;controls&lt;/span&gt;:&lt;span style="color: #800000;"&gt;ChildWindow&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;This Silverlight xaml code contains the metadata information for the dialog, and for the 4 controls we discussed earlier. &lt;/li&gt;
&lt;li&gt;We need to do another step to add some code for the Silverlight control, so let&amp;rsquo;s add another file. &lt;/li&gt;
&lt;li&gt;Right click the &amp;ldquo;UserCode&amp;rdquo; folder and select &amp;ldquo;Add &amp;ndash;&amp;gt; Class&amp;rdquo; &lt;/li&gt;
&lt;li&gt;Name the class &amp;ldquo;SelectFileWindow.cs&amp;rdquo; and copy the below code into the class:
&lt;pre style="background-color: #fbfbfb; min-height: 40px; width: 577px; height: 397px; overflow: auto; border: #cecece 1px solid; padding: 5px;"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #008000;"&gt;//' Copyright &amp;copy; Microsoft Corporation.  All Rights Reserved.&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #008000;"&gt;//' This code released under the terms of the &lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #008000;"&gt;//' Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; System;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; System.IO;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; System.Windows;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; System.Windows.Controls;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;namespace&lt;/span&gt; LightSwitchApplication.UserCode
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;{
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; partial &lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; SelectFileWindow : ChildWindow
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; SelectFileWindow()
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            InitializeComponent();
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;private&lt;/span&gt; FileStream documentStream;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; FileStream DocumentStream
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff;"&gt;get&lt;/span&gt; { &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; documentStream; }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff;"&gt;set&lt;/span&gt; { documentStream = &lt;span style="color: #0000ff;"&gt;value&lt;/span&gt;; }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// OK Button&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; OKButton_Click(&lt;span style="color: #0000ff;"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.DialogResult = &lt;span style="color: #0000ff;"&gt;true&lt;/span&gt;;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// Cancel button&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; CancelButton_Click(&lt;span style="color: #0000ff;"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.DialogResult = &lt;span style="color: #0000ff;"&gt;false&lt;/span&gt;;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// Browse button&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; BrowseButton_Click(&lt;span style="color: #0000ff;"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            OpenFileDialog openFileDialog = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; OpenFileDialog();
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #008000;"&gt;// Limit the dialog to only show ".csv" files,&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #008000;"&gt;// modify this as necessary to allow other file types&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            openFileDialog.Filter = "&lt;span style="color: #8b0000;"&gt;csv files (*.csv)|*.csv&lt;/span&gt;";
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            openFileDialog.FilterIndex = 1;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (openFileDialog.ShowDialog() == &lt;span style="color: #0000ff;"&gt;true&lt;/span&gt;)
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.FileTextBox.Text = openFileDialog.File.Name;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.FileTextBox.IsReadOnly = &lt;span style="color: #0000ff;"&gt;true&lt;/span&gt;;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                System.IO.FileStream myStream = openFileDialog.File.OpenRead();
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                documentStream = myStream;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;}
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;This partial class for our &amp;ldquo;SelectFileWindow&amp;rdquo; Silverlight dialog contains a few basic things: &lt;ol&gt;
&lt;li&gt;The methods for our button controls &lt;/li&gt;
&lt;li&gt;The Browse button has code in it to create a System.Windows.Controls.OpenFileDialog object which we use to open up our Open File Dialog to allow the user to select a .csv file.&amp;nbsp; Once we open the file we store the file&amp;rsquo;s data into a FileStream property on our SelectFileWindow class. &lt;/li&gt;
&lt;li&gt;A public FileStream property called DocumentStream that contains the data for the .csv file we want to import &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;We need to add a reference to the Silverlight dll we are using, so in Solution Explorer, navigate to &amp;ldquo;Client &amp;ndash;&amp;gt; References&amp;rdquo;, right click and select &amp;ldquo;Add Reference&amp;hellip;&amp;rdquo; &lt;/li&gt;
&lt;li&gt;Add a .NET reference to the System.Windows.Controls assembly &lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;&lt;/h3&gt;
&lt;h3&gt;Add a Simple Class to Parse the .CSV File&lt;/h3&gt;
&lt;p&gt;For the sake of modularity and encapsulation we will create a separate class to handle the parsing of the .csv file.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Add a new User Code class &amp;ndash; in Solution Explorer, right click the &amp;ldquo;Client-&amp;gt;UserCode&amp;rdquo; folder, and select &amp;ldquo;Add &amp;ndash;&amp;gt; Class&amp;rdquo;. &lt;/li&gt;
&lt;li&gt;Name the class &amp;ldquo;ImportDataFile.cs&amp;rdquo; and add the below code:
&lt;pre style="background-color: #fbfbfb; min-height: 40px; width: 563px; height: 546px; overflow: auto; border: #cecece 1px solid; padding: 5px;"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #008000;"&gt;//' Copyright &amp;copy; Microsoft Corporation.  All Rights Reserved.&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #008000;"&gt;//' This code released under the terms of the &lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #008000;"&gt;//' Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; System;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; System.IO;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff;"&gt;namespace&lt;/span&gt; LightSwitchApplication.UserCode
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;{
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; ImportDataFile
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// Import data from a comma delimited stream&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// And using the workspace that was passed in, insert the imported data&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// so it displays on the user's screen&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; ImportCommaDelimitedStream(FileStream fileStream, DataWorkspace dataWorkspace)
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            List&amp;lt;&lt;span style="color: #0000ff;"&gt;string&lt;/span&gt;[]&amp;gt; parsedData = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; List&amp;lt;&lt;span style="color: #0000ff;"&gt;string&lt;/span&gt;[]&amp;gt;();
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; (StreamReader streamReader = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; StreamReader(fileStream))
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #0000ff;"&gt;string&lt;/span&gt; line;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #0000ff;"&gt;string&lt;/span&gt;[] row;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #0000ff;"&gt;while&lt;/span&gt; ((line = streamReader.ReadLine()) != &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;)
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                    row = line.Split(',');
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                    parsedData.Add(row);
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            AddData(parsedData, dataWorkspace);
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// Take in a list of string arrays which contains&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// all the parsed data for our Contacts entity&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; AddData(List&amp;lt;&lt;span style="color: #0000ff;"&gt;string&lt;/span&gt;[]&amp;gt; dataList, DataWorkspace dataWorkspace)
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff;"&gt;foreach&lt;/span&gt; (&lt;span style="color: #0000ff;"&gt;string&lt;/span&gt;[] row &lt;span style="color: #0000ff;"&gt;in&lt;/span&gt; dataList)
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                Contact contact = dataWorkspace.ApplicationData.Contacts.AddNew();
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                contact.FirstName = row[0];
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                contact.MiddleName = row[1];
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                contact.LastName = row[2];
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                contact.AddressLine1 = row[3];
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                contact.AddressLine2 = row[4];
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                contact.City = row[5];
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                contact.State = row[6];
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                contact.ZipCode = row[7];
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                contact.Country = row[8];
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                contact.PhoneNumber1 = row[9];
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                contact.PhoneNumber2 = row[10];
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                contact.BirthDate = DateTime.Parse(row[11]);
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                contact.MiscellaneousInformation = row[12];
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;}
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;This class contains two basic methods: &lt;ol&gt;
&lt;li&gt;The AddData() method which iterates over a List of string arrays, and creates a new Contact in our DataWorkspace for each string array. &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;The ImportCommaDelimitedStream() method takes in a FileStream object (our .csv file, which we can get off our SelectFileWindow class that we just made), and a DataWorkspace object.&amp;nbsp; The method reads the lines in the FileStream object, parses off each &amp;ldquo;comma&amp;rdquo;, stores each line in a string array and then invokes the AddData() method. &lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;&lt;/h3&gt;
&lt;h3&gt;Add Import Data Button Code&lt;/h3&gt;
&lt;p&gt;Let&amp;rsquo;s do the final bit of coding now by adding the code to our &amp;ldquo;Import Data&amp;rdquo; button. &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;To get to our button, switch the back to &amp;ldquo;Logical View&amp;rdquo; &lt;ol&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/0003.image_5F00_2DDD5EFD.png"&gt;&lt;img height="124" width="244" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/1376.image_5F00_thumb_5F00_745A4F05.png" alt="image" border="0" title="image" style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" /&gt;&lt;/a&gt; &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;Open up the Screen Designer for the EditableContactsGrid screen &lt;/li&gt;
&lt;li&gt;Navigate to the Import Data button, right click and select &amp;ldquo;Edit Execute Code&amp;rdquo; &lt;ol&gt;
&lt;li&gt;We should now be in the EditableContactsGrid partial class &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;We need a &amp;ldquo;using&amp;rdquo; statement for our Client UserCode that we added, so add the following using statement to this class: &amp;ldquo;using LightSwitchApplication.UserCode&amp;rdquo; &lt;/li&gt;
&lt;li&gt;We also need another using statement so we can reference the &amp;ldquo;Dispatchers&amp;rdquo; class, so add the following using statement to this class as well: &amp;ldquo;using Microsoft.LightSwitch.Threading&amp;rdquo; &lt;/li&gt;
&lt;li&gt;Paste the following code into your ImportData_Execute() button method
&lt;pre style="background-color: #fbfbfb; min-height: 40px; width: 550px; height: 388px; overflow: auto; border: #cecece 1px solid; padding: 5px;"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// Import Data button method&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        partial &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; ImportData_Execute()
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #008000;"&gt;// To invoke our own dialog, we have to do this inside of the "Main" Dispatcher&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #008000;"&gt;// And, since this is a web application, we can't directly invoke the Silverlight OpenFileDialog&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #008000;"&gt;// class, we have to first invoke our own Silverlight custom control (i.e. SelectFileWindow)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #008000;"&gt;// and that control will be able to invoke the OpenFileDialog class (via the Browse button)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            Dispatchers.Main.BeginInvoke(() =&amp;gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                SelectFileWindow selectFileWindow = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; SelectFileWindow();
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                selectFileWindow.Closed += &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; EventHandler(selectFileWindow_Closed);
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                selectFileWindow.Show();
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            });
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// Invoked when our custom Silverlight window closes&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080;"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; selectFileWindow_Closed(&lt;span style="color: #0000ff;"&gt;object&lt;/span&gt; sender, EventArgs e)
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            SelectFileWindow selectFileWindow = (SelectFileWindow)sender;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #008000;"&gt;// Continue if they hit the OK button AND they selected a file&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (selectFileWindow.DialogResult == &lt;span style="color: #0000ff;"&gt;true&lt;/span&gt; &amp;amp;&amp;amp; (selectFileWindow.DocumentStream != &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;))
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                ImportDataFile.ImportCommaDelimitedStream(selectFileWindow.DocumentStream, &lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.DataWorkspace);
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                selectFileWindow.DocumentStream.Close();
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        }&lt;/pre&gt;
&lt;/pre&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Here&amp;rsquo;s what&amp;rsquo;s going on at a high level when the Import Data button is clicked:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&amp;nbsp;&lt;ol&gt;
&lt;li&gt;The button is clicked &lt;/li&gt;
&lt;li&gt;An instance of our Silverlight dialog, SelectFileWindow, is created &lt;/li&gt;
&lt;li&gt;The dialog is opened by calling the Show() method &lt;/li&gt;
&lt;li&gt;An EventHandler is added to the SelectFileWindow Closed event so that the &amp;ldquo;selectFileWindow_Closed()&amp;rdquo; method is invoked after the dialog is closed &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Optional Reading&lt;/strong&gt; &amp;ndash; Here is a lower level explanation of what is going on in this button method:&lt;/p&gt;
&lt;blockquote&gt;
&lt;table width="400" cellpadding="2" cellspacing="0" border="1"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td width="400" valign="top"&gt;
&lt;p&gt;&lt;strong&gt;Technical Stuff: &lt;/strong&gt;Since the Import Data button code does NOT by default run inside the Main UI thread, we have to invoke the &amp;ldquo;Main&amp;rdquo; thread (or Dispatcher) before calling our Silverlight dialog. That is the reason for wrapping this code inside the Dispatchers.Main.BeginInvoke() method.&lt;/p&gt;
&lt;p&gt;So why can&amp;rsquo;t we just open the OpenFileDialog directly? Why do we have to open a Silverlight dialog which then launches an OpenFileDialog? &lt;/p&gt;
&lt;p&gt;Well, this is really what makes the web application scenario different from the Desktop application. If you try to directly launch the OpenFileDialog you will get a &amp;ldquo;Dialogs must be user-initiated&amp;rdquo; error message. This is because Silverlight dialogs (like OpenFileDialog) can only be opened from &amp;ldquo;user actions&amp;rdquo;, like a button clicked event handler. The reason why this won&amp;rsquo;t work with LightSwitch is because we invoke the button logic asynchronously, so the Import Data button code is not considered to be &amp;ldquo;user-initiated&amp;rdquo;.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/blockquote&gt;
&lt;h3&gt;&lt;/h3&gt;
&lt;h3&gt;Run That Thing!&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;In Solution Explorer, right click the ImportDataFromAWebApp project, and select &amp;ldquo;Build&amp;rdquo;. &lt;/li&gt;
&lt;li&gt;After the build, press F5 to run your project &lt;/li&gt;
&lt;li&gt;You should see inside the Editable Contacts Grid screen&amp;rsquo;s command bar an &amp;ldquo;Import Data&amp;rdquo; button: &lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/7178.image_5F00_391D3537.png"&gt;&lt;img height="203" width="516" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/5123.image_5F00_thumb_5F00_74046800.png" alt="image" border="0" title="image" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" /&gt;&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;Click the button, and you should see the SelectFileWindow Silverlight dialog we created &lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/2046.image_5F00_678CDCA5.png"&gt;&lt;img height="338" width="511" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/5850.image_5F00_thumb_5F00_7BA5F92E.png" alt="image" border="0" title="image" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" /&gt;&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;Click the &amp;ldquo;Browse&amp;rdquo; button inside our SelectFileWindow dialog to open up the OpenFileDialog &lt;/li&gt;
&lt;li&gt;Select a .csv file to import (I have one at the end of this blog which can be used) &lt;ol&gt;&lt;!--EndFragment--&gt;&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;Click &amp;ldquo;OK&amp;rdquo; to import the data &lt;/li&gt;
&lt;li&gt;You should now see your data displayed inside your workspace &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The C# and VB.NET code is available on MSDN Code Gallery here: &lt;a href="http://code.msdn.microsoft.com/Visual-Studio-LightSwitch-1f8aa17e"&gt;http://code.msdn.microsoft.com/Visual-Studio-LightSwitch-1f8aa17e&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Let me know if you have questions.&amp;nbsp; Enjoy!&lt;/p&gt;
&lt;p&gt;Matt Sampson -&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-65-metablogapi/6840.wlEmoticon_2D00_martiniglass_5F00_613CD85D.png" alt="Martini glass" class="wlEmoticon wlEmoticon-martiniglass" style="border-style: none;" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10162939" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/LightSwitch/">LightSwitch</category><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/Visual+Studio+LightSwitch/">Visual Studio LightSwitch</category><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/Web+Application/">Web Application</category><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/SilverLight/">SilverLight</category></item><item><title>How Do I: Export Data to a Word Mailing Labels Document</title><link>http://blogs.msdn.com/b/rmattsampson/archive/2011/04/25/how-do-i-export-data-to-a-word-labels-document.aspx</link><pubDate>Tue, 26 Apr 2011 04:55:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10154152</guid><dc:creator>Matt Sampson</dc:creator><slash:comments>9</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/rmattsampson/rsscomments.aspx?WeblogPostID=10154152</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/rmattsampson/commentapi.aspx?WeblogPostID=10154152</wfw:comment><comments>http://blogs.msdn.com/b/rmattsampson/archive/2011/04/25/how-do-i-export-data-to-a-word-labels-document.aspx#comments</comments><description>&lt;p&gt;I&amp;rsquo;m going to start off my first &amp;ldquo;How Do I&amp;rdquo; post with a simple application that exports the application&amp;rsquo;s data to a Word Mailing Label Document.&amp;nbsp; At the end of the blog you&amp;rsquo;ll find links to the the VS LightSwitch project code for both C# and VB.Net.&lt;/p&gt;
&lt;h3&gt;Back Story&lt;/h3&gt;
&lt;p&gt;I was sending several dozen birth announcements recently to friends and family, and realized that I needed a better way to manage all the addresses and contact information I had floating around my house.&amp;nbsp; That, and needing to brush up on my Visual Studio LightSwitch (LS) skills, led to the creation of a Contacts manager application.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;I was able to quickly create an application using LS which I thought would meet everyone&amp;rsquo;s needs.&amp;nbsp; But my wife insisted she wasn&amp;rsquo;t interested in using it unless it could export all the contact information to a Word Document.&amp;nbsp; Fortunately, I was able to get a start on figuring out how to add this functionality by reading Beth Massi&amp;rsquo;s &lt;a target="_blank" href="http://blogs.msdn.com/b/bethmassi/archive/2010/09/10/using-microsoft-word-to-create-reports-for-lightswitch-or-silverlight.aspx"&gt;blog post on creating reports in Word for LS&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;Using the System.Runtime.InteropServices.Automation.AutomationFactory class I was able to do just what I needed all from the Client side.&lt;/p&gt;
&lt;p&gt;So let&amp;rsquo;s get started creating a very basic application to manage our contacts, then add some functionality to create a mailing label document using the COM Object and the AutomationFactory class..&lt;/p&gt;
&lt;h3&gt;Step 1 &amp;ndash; Create our simple Contacts table and screen&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Create a Visual Studio LightSwitch C# or VB Project &lt;/li&gt;
&lt;li&gt;Add a table &amp;ndash; Contact, with the following properties: &lt;ol&gt;
&lt;li&gt;FirstName | String | Required &lt;/li&gt;
&lt;li&gt;MiddleName | String &lt;/li&gt;
&lt;li&gt;LastName | String | Required &lt;/li&gt;
&lt;li&gt;AddressLine1 | String &lt;/li&gt;
&lt;li&gt;AddressLine2 | String &lt;/li&gt;
&lt;li&gt;City | String &lt;/li&gt;
&lt;li&gt;State | String &lt;/li&gt;
&lt;li&gt;ZipCode | String &lt;/li&gt;
&lt;li&gt;Country | String &lt;/li&gt;
&lt;li&gt;PhoneNumber1 | PhoneNumber &lt;/li&gt;
&lt;li&gt;PhoneNumber2 | PhoneNumber &lt;/li&gt;
&lt;li&gt;BirthDate | Date &lt;/li&gt;
&lt;li&gt;MiscellaneousInformation | String &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;Add a List and Details screen, called Contacts, which uses the Contacts table data &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;OPTIONAL - &lt;/strong&gt;I made some minor changes to the &amp;ldquo;List&amp;rdquo; portion of the screen &lt;ol&gt;
&lt;li&gt;In the screen designer, navigate to Columns Layout-&amp;gt; Rows Layout &amp;ndash;&amp;gt; List and change &amp;ldquo;List&amp;rdquo; to &amp;ldquo;Data Grid&amp;rdquo; using the drop down arrow &lt;/li&gt;
&lt;li&gt;Under Columns Layout &amp;ndash;&amp;gt; Rows Layout &amp;ndash;&amp;gt; Data Grid &amp;ndash;&amp;gt; Data Grid Row remove all fields except for &amp;ldquo;First Name&amp;rdquo; and &amp;ldquo;Last Name&amp;rdquo; &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;In the screen designer, under Columns Layout &amp;ndash;&amp;gt; Screen Command Bar add a button &lt;/li&gt;
&lt;li&gt;Call the button &amp;ldquo;Export to Word Mailing Label Document&amp;rdquo; (we&amp;rsquo;ll add the code later) &lt;/li&gt;
&lt;li&gt;Your screen designer and Solution Explorer should look something like this now: &lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-44-65-metablogapi/7245.image7_5F00_696C2120.png"&gt;&lt;img height="588" width="568" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-44-65-metablogapi/6278.image7_5F00_thumb_5F00_5A554246.png" alt="image" border="0" title="image" style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" /&gt;&lt;/a&gt; &lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;Step 2 &amp;ndash; Add Client side code to generate our Word document&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;In Solution Explorer, click the drop down arrow next to the &amp;ldquo;Logical View&amp;rdquo; button and select &amp;ldquo;File View&amp;rdquo; &lt;ol&gt;
&lt;li&gt;The Solution Explorer tree switches to the File View mode which displays all the code under the Client, Common and Server projects &lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-44-65-metablogapi/4466.image_5F00_34C2E4DD.png"&gt;&lt;img height="184" width="281" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-44-65-metablogapi/6114.image_5F00_thumb_5F00_1AEEAEAE.png" alt="image" border="0" title="image" style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" /&gt;&lt;/a&gt; &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;We are going to add our own User Class to the Client project, so right click the Client project, and select Add &amp;ndash;&amp;gt; Class. &lt;/li&gt;
&lt;li&gt;Add a new Class called ExportToWord.&amp;nbsp; Paste the below code into the class:
&lt;pre style="background-color: #fbfbfb; min-height: 40px; width: 612px; height: 430px; overflow: auto; border: #cecece 1px solid; padding: 5px;"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #008000"&gt;//' Copyright &amp;copy; Microsoft Corporation.  All Rights Reserved.&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #008000"&gt;//' This code released under the terms of the &lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #008000"&gt;//' Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; Microsoft.LightSwitch;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; Microsoft.LightSwitch.Framework;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Linq;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Text;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.IO;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; LightSwitchApplication.UserCode
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;{
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; ExportToWord
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080"&gt;/// Create a mailing label document based upon our Contacts and their corresponding address information&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080"&gt;/// &amp;lt;returns&amp;gt;A byte array containing the generated Word Mailing Label Document&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[] ExportToMailingLabelDocumentWithCOM()
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            Object fileName = String.Concat(
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                @"&lt;span style="color: #8b0000"&gt;\Contacts_&lt;/span&gt;" + System.DateTime.UtcNow.ToFileTimeUtc() + "&lt;span style="color: #8b0000"&gt;.docx&lt;/span&gt;");
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            Object labelName = "&lt;span style="color: #8b0000"&gt;8660 Easy Peel Address Labels&lt;/span&gt;";
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            dynamic wordObject = System.Runtime.InteropServices.Automation.AutomationFactory.CreateObject("&lt;span style="color: #8b0000"&gt;Word.Application&lt;/span&gt;");
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            wordObject.Documents.Add();
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #008000"&gt;// Create an empty mailing label document&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            dynamic mailingLabelDoc = wordObject.MailingLabel.CreateNewDocument(&lt;span style="color: #0000ff"&gt;ref&lt;/span&gt; labelName);
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff"&gt;try&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #008000"&gt;// Format the contacts address information&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; contacts = FormatContactsAddressInformation();
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #008000"&gt;// Populate the word document with labels&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                PopulateLabels(contacts, mailingLabelDoc);
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #008000"&gt;// Save our label doc as the default word format (i.e. docx)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                mailingLabelDoc.SaveAs2(&lt;span style="color: #0000ff"&gt;ref&lt;/span&gt; fileName);
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff"&gt;catch&lt;/span&gt; (Exception e)
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; InvalidOperationException("&lt;span style="color: #8b0000"&gt;Failed to create document&lt;/span&gt;", e);
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff"&gt;finally&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #008000"&gt;// Wait for Word to shut down to ensure the document is released&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (mailingLabelDoc != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                    mailingLabelDoc.Close();
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (wordObject != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                    wordObject.Quit();
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #008000"&gt;// Cast our wordObject as IDisposable so that we can &lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #008000"&gt;// invoke .Dispose() and be sure the COM object is released&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                IDisposable disposable = wordObject &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; IDisposable;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (disposable != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                    disposable.Dispose();
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #008000"&gt;// Take our newly created word document, and stick into our a Byte[] array&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[] buffer = File.ReadAllBytes((&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;)fileName);
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #008000"&gt;// Delete the file now that we are done with it&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #008000"&gt;// We'll pass back the byte[] buffer and let the user choose a filename and location&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            File.Delete((&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;)fileName);
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; buffer;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080"&gt;/// Formats each contacts address information and stores the data into a List&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; FormatContactsAddressInformation()
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #008000"&gt;// Populate a List with our contacts and their address information&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; contacts = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt;();
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            EntitySet&amp;lt;Contact&amp;gt; contactsSet = Application.Current.CreateDataWorkspace().ApplicationData.Contacts;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (Contact contact &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; contactsSet.OrderBy(x =&amp;gt; x.LastName))
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; formattedAddress = contact.FirstName + "&lt;span style="color: #8b0000"&gt; &lt;/span&gt;" + contact.LastName + Environment.NewLine + contact.AddressLine1 + Environment.NewLine;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!String.IsNullOrEmpty(contact.AddressLine2))
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                    formattedAddress += contact.AddressLine2 + Environment.NewLine;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                formattedAddress += contact.City + "&lt;span style="color: #8b0000"&gt; &lt;/span&gt;" + contact.State + "&lt;span style="color: #8b0000"&gt; &lt;/span&gt;" + contact.ZipCode + Environment.NewLine;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!String.IsNullOrEmpty(contact.Country))
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                    formattedAddress += contact.Country;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                contacts.Add(formattedAddress);
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; contacts;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080"&gt;/// Populate the Labels in a given word document with our Contact's information&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; PopulateLabels(List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; contacts, dynamic wordDocument)
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            dynamic docTable = wordDocument.Tables[1];
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #008000"&gt;// Starting at row 1, iterate through each row and column in the Mailing Label's Table&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #008000"&gt;// And for each cell, insert our Contact's address information&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; row = 1;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; currentContactIndex = 0;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff"&gt;while&lt;/span&gt; (currentContactIndex &amp;lt; contacts.Count)
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #008000"&gt;// Skip even numbered columns since they are "divider" columns and not intended for cell text&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; column = 1; column &amp;lt;= docTable.Columns.Count; column += 2)
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                    &lt;span style="color: #008000"&gt;// If we've run out of Contacts, break out&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (currentContactIndex &amp;gt;= contacts.Count)
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                    {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                        &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                    }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                    docTable.Cell(row, column).Range.Text = contacts[currentContactIndex];
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                    docTable.Cell(row, column).Range.ParagraphFormat.Alignment = 1;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                    docTable.Cell(row, column).Range.Cells.VerticalAlignment = 1;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                    docTable.Cell(row, column).Range.Rows.Alignment = 1;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                    currentContactIndex++;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #008000"&gt;// Keep track of what row we are on in our table&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                row++;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #008000"&gt;// Check to see if we've run out of rows in our table&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (row &amp;gt; docTable.Rows.Count)
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                    &lt;span style="color: #008000"&gt;// Add a new row to our table&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                    docTable.Rows.Add();
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;}
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;Here&amp;rsquo;s the breakdown of what the ExportToWord&amp;rsquo;s class methods are doing: 
&lt;ul&gt;
&lt;li&gt;
&lt;h5&gt;PopulateLabels():&lt;/h5&gt;
&lt;ol&gt;
&lt;li&gt;Iterates over the table cell&amp;rsquo;s in a Word document instance. &lt;/li&gt;
&lt;li&gt;Populates each cell with a Contact&amp;rsquo;s address information. &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;
&lt;h5&gt;FormatContactsAddressInformation():&lt;/h5&gt;
&lt;ol&gt;
&lt;li&gt;Iterates over each Contact in the SQL database, ordering the contacts by LastName . &lt;/li&gt;
&lt;li&gt;Takes the necessary address information from each contact and formats it into a nice looking string. &lt;/li&gt;
&lt;li&gt;Each string is added to a List of address information. &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;
&lt;h5&gt;ExportToMailingLabelDocumentWithCOM():&lt;/h5&gt;
&lt;ol&gt;
&lt;li&gt;Creates a Word.Application COM Object. &lt;/li&gt;
&lt;li&gt;Creates an empty Mailing Label Document based off the &amp;ldquo;8660 Easy Peel Address Labels&amp;rdquo; template. &lt;/li&gt;
&lt;li&gt;Calls FormatContactsAddressInformation() and PopulateLabels() &lt;/li&gt;
&lt;li&gt;Now the mailing labels are populated with the correct data &lt;/li&gt;
&lt;li&gt;Save the document and then store it in a byte array &lt;/li&gt;
&lt;li&gt;Delete the original document, and pass the byte array back to the calling method &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;Step 4 &amp;ndash; Add Button code to call into our ExportToWord class&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;We are now going to add code to our button to invoke the code we added in the previous steps. &lt;/li&gt;
&lt;li&gt;In the screen designer, under Columns Layout &amp;ndash;&amp;gt; Screen Command Bar, right click the &amp;ldquo;Export to Word Mailing Label Document&amp;rdquo; button and select &amp;ldquo;Edit Execute code&amp;rdquo; &lt;/li&gt;
&lt;li&gt;Paste the following code into the your button&amp;rsquo;s method :
&lt;pre style="background-color: #fbfbfb; min-height: 40px; width: 582px; height: 84px; overflow: auto; border: #cecece 1px solid; padding: 5px;"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #008000"&gt;// Call into our Client User Class to create the word document, then return it as a byte array&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[] wordDocument = ExportToWord.ExportToMailingLabelDocumentWithCOM();
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.DisplaySaveAsFileDialog(wordDocument);&lt;/pre&gt;
&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;This won&amp;rsquo;t compile now until we add the DisplaySaveAsFileDialog() method to the same class as well.&amp;nbsp; So copy and paste the below method into the class:
&lt;pre style="background-color: #fbfbfb; min-height: 40px; width: 582px; height: 362px; overflow: auto; border: #cecece 1px solid; padding: 5px;"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080"&gt;/// This method will display a SaveAsFileDialog to the user to save&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080"&gt;/// a given file buffer&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #808080"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; DisplaySaveAsFileDialog(&lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[] fileBuffer)
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #008000"&gt;// Need to switch back to the Main UI thread before we can pop up any dialogs.&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #008000"&gt;// We need to do this, because by default the button code operates outside of the main&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #008000"&gt;// UI thread, and the only way the user is going to see a Dialog box is for it to &lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            &lt;span style="color: #008000"&gt;// appear inside the main UI thread.&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            Dispatchers.Main.BeginInvoke(() =&amp;gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                SaveFileDialog dialog = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SaveFileDialog();
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                dialog.DefaultExt = "&lt;span style="color: #8b0000"&gt;.docx&lt;/span&gt;";
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; dialogResult = (&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt;)dialog.ShowDialog();
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (dialogResult == &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;)
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                    &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (FileStream fileStream = (FileStream)dialog.OpenFile())
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                    {
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                        fileStream.Write(fileBuffer, 0, fileBuffer.Length);
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                        fileStream.Close();
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                    }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;                }
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            });
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        }&lt;/pre&gt;
&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;And then, we will need to add these using statements.
&lt;pre style="background-color: #fbfbfb; min-height: 40px; width: 550px; overflow: auto; border: #cecece 1px solid; padding: 5px;"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows.Controls;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; Microsoft.LightSwitch.Threading;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #008000"&gt;//Namespace of our ExportToWord class&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; LightSwitchApplication.UserCode;&lt;/pre&gt;
&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;In addition to invoking the ExportToWord.ExportToMailingLabelDocumentWithCOM() method we wrote, this button code will display a Save File Dialog so that the user can decide where on their client side machine they want to save the Word document. &lt;/li&gt;
&lt;li&gt;To create the file, the Save File Dialog will read in the byte[] array which we returned earlier from the ExportToMailingLabelDocumentWithCOM() method. &lt;/li&gt;
&lt;li&gt;As the code comments in DisplaySaveAsFileDialog() state, to invoke the Save File Dialog, we have to switch to the main UI thread since the button&amp;rsquo;s code operates outside the main UI thread.&amp;nbsp; And if we want to do something like pop up a dialog, it has to be done in the main UI thread. &lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;&lt;/h3&gt;
&lt;h3&gt;Step 6 &amp;ndash; Run it&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Compile and run our Contacts application now.&amp;nbsp; &lt;/li&gt;
&lt;li&gt;Enter in some Contact information. &lt;/li&gt;
&lt;li&gt;We should have a screen looking something like this: &lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-44-65-metablogapi/6675.image8_5F00_47A0488F.png"&gt;&lt;img height="374" width="617" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-44-65-metablogapi/1805.image8_5F00_thumb_5F00_1227866A.png" alt="image" border="0" title="image" style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" /&gt;&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;Now if we click the &amp;ldquo;Export to Word Mailing Label Document&amp;rdquo; button, our application will display a &amp;ldquo;Save As&amp;rdquo; File dialog. &lt;/li&gt;
&lt;li&gt;After specifying a name for our file, we should be able to open it and see our mailing labels. &lt;ol&gt;
&lt;li&gt;I specified the 8660 Easy Peel Address Labels in our code when generating the Word document, but you could customize this code for a different mailing label template if needed. &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Code samples are here: &lt;a href="http://code.msdn.microsoft.com/Visual-Studio-LightSwitch-d2ca025e"&gt;http://code.msdn.microsoft.com/Visual-Studio-LightSwitch-d2ca025e&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In the near future I should have another blog post on how to create a document on the Server side (allowing you to take advantage of Intellisense) and transfer that document back to the Client.&lt;/p&gt;
&lt;p&gt;Let me know if you have any questions! &lt;/p&gt;
&lt;p&gt;Thanks -&amp;nbsp; Matt Sampson &lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-44-65-metablogapi/0640.wlEmoticon_2D00_martiniglass_5F00_76741EC8.png" alt="Martini glass" class="wlEmoticon wlEmoticon-martiniglass" style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10154152" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/LightSwitch/">LightSwitch</category><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/Word/">Word</category><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/COM/">COM</category></item><item><title>Fargo VS LightSwitch Team</title><link>http://blogs.msdn.com/b/rmattsampson/archive/2011/04/14/fargo-vs-lightswitch-team.aspx</link><pubDate>Thu, 14 Apr 2011 13:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10153872</guid><dc:creator>Matt Sampson</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/rmattsampson/rsscomments.aspx?WeblogPostID=10153872</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/rmattsampson/commentapi.aspx?WeblogPostID=10153872</wfw:comment><comments>http://blogs.msdn.com/b/rmattsampson/archive/2011/04/14/fargo-vs-lightswitch-team.aspx#comments</comments><description>&lt;p&gt;Hello All,&lt;/p&gt;
&lt;p&gt;Time to start a new chapter in my life at Microsoft.&amp;nbsp; I officiall started on the Visual Studio Lightswitch team here in Fargo, ND on April 4th.&lt;/p&gt;
&lt;p&gt;I should be posting some good stuff about Lightswitch on this blog shortly.&lt;/p&gt;
&lt;p&gt;Stay tuned.&lt;/p&gt;
&lt;p&gt;Matt Sampson&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10153872" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/rmattsampson/archive/tags/Fargo/">Fargo</category></item></channel></rss>