An advantage of using Silverlight is the fact that the entire app is cached locally. While this may take a while to download initially, after everything is downloaded the app runs very very fast and only requires you download information asynchronously from a web service. The only problem is, what if you make changes? Since the app is cached those changes are sometimes not downloaded automatically. So what to do? Lars Holm Jensen wrote a nifty little post that shows how you can determine when the last time the silverlight package was was deployed by reading the datetime stamp on the ‘xap’ file. Just in case you didn’t click on the link, here’s the code:
<object id="Xaml1" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%"> <% string orgSourceValue = @"ClientBin/SilverlightApp.xap"; string param; if (System.Diagnostics.Debugger.IsAttached) param = "<param name=\"source\" value=\"" + orgSourceValue + "\" />"; else { string xappath = HttpContext.Current.Server.MapPath(@"") + @"\" + orgSourceValue; DateTime xapCreationDate = System.IO.File.GetLastWriteTime(xappath); param = "<param name=\"source\" value=\"" + orgSourceValue + "?ignore=" + xapCreationDate.ToString() + "\" />"; } Response.Write(param); %> <param name="onError" value="onSilverlightError" />
The ‘if’ statement checks to see if your debugging. If you are, then grab the latest/greatest. If not, then it’s assumed that you are in production mode and then it checks to see if you have the latest and greatest. If you don’t, then download the latest version. Thanks Lars!
Tags: C#, Silverlight
