Archive for January, 2011

FYI – refreshing a Silverlight XAP file

Something that will save you some hair and time, I know that I have very little of the former left. No, really – most of my hair left me in my twenties.

Anways, I was experimenting with a Silverlight application on my  hosting provider, and I would make a change, upload the XAP, and refresh the browser, but nothing would happen. I would close the browser tab and reopen it, and the change I just made wouldn’t appear.

That was because I needed to open a whole new browser, not a new tab. After I opened the new browser window, then my changes were displayed. I would have liked to have remembered that earlier in the morning and saved myself an hour, but this time the lesson has really sunk into my brain.


Leave a comment

Refreshing SQL Express database clears Session variables

I can’t vouch for the validity of this tip under all conditions, but while testing a Silverlight / ASP.NET  project, I queried the SQL Express database that was the main data source for my project, and when I went back to the ASP.NET page I was viewing, I received an “Object reference not set to an instance of an object error ” exception.

 Apparently, refreshing the database – in my case, the table that stored user information – will clear the Session variables. This is a very useful thing to know – it makes it easy to dig deep into the application, then clear the Session variables, and keep on trying to work in the application. It will let me know what the heck will happen if something really goes wrong.

Leave a comment

Asychronously sending e-mail, lambda expression edition

Is there anything cooler, code-wise, than lambda expressions? It is what I envisioned when I wanted to be a computer programmer, writing programs with obscure syntax surrounding my huge pieces of electronics and bubbling cauldrons.

With lambda expressions, we get this. Here is one that uses the SmtpClient in ASP.NET to asynchronously send a message. You could do something interesting when the function checks for success or failure, but I didn’t.

MailMessage Message = new MailMessage(,;
Message.Subject = "Test asyc";
Message.Body = "Body text!";         
SmtpClient Smtp = new SmtpClient("");         
Smtp.SendCompleted += new SendCompletedEventHandler((Object sender, System.ComponentModel.AsyncCompletedEventArgs e) =>
            if (e.Error != null)
                string test = e.Error.Message;
                string Success = string.Empty;
        Smtp.SendAsync(Message, Message);

Leave a comment

Communicating between Silverlight and ASP.NET via JavaScript

You love Silverlight, you love ASP.NET. You want Silverlight and ASP.NET to love each other. Enter the third party in the technology love triangle, JavaScript.

In my scenario, I had an ASP.NET page that opened another page that hosted a Silverlight control. When the user selected some data and clicked the Save button, the Silverlight window should pass that data to the original ASP.NET page, as well as close the opened window.

So in the opening page, I use some JavaScript to open a new window:'SilverlightPage.aspx', 'MyWindow');

After I’ve done wonderful things in Silverlight, I click my Save button:

<Button x:Name="SaveProperty" Content="Save" Click="SaveProperty_Click"  />

Which calls it’s code-behind function. Here is the magic, the HtmlPage.Window.Invoke function. In my code, I use it to call a JavaScript function defined in SilverlightPage.aspx, passing in the values from two TextBox controls in Silverlight.

 private void SaveProperty_Click(object sender, RoutedEventArgs e)
 HtmlPage.Window.Invoke("PopulateOneTwo ", TextBox1.Text, TextBox2.Text);

All the PopulateOneTwo function does is pass on the variables from Silverlight to the calling page, then close itself. Remember, PopulateOneTwo  is defined in SilverlightPage.aspx, the page that holds the Silverlight control.

function PopulateOneTwo(varOne, varTwo) {
window.opener.PopulateValues(varOne, varTwo);

Back to the original ASP.NET page, I have the PopulateValues function to actually take the values passed from the SilverlightPage.aspx (and the Silverlight code) and populate the TextBox controls:

function PopulateValues(varFirst,varSecond) 
     var One= document.getElementById("txtOne");
     var Two= document.getElementById("txtTwo");
     One.value = varFirst; 
     Two.value = varSecond;

<asp:TextBox ID="txtOne" runat="server"/> 
<asp:TextBox ID="txtTwo" runat="server"/>

Bada bing, done, and I have the values passed into an ASP.NET from Silverlight.

Leave a comment

Display passwords stored in your browser

I found this very useful tip at itickr.

Ever forget a password, but it’s still stored in a password textbox on your browser via the autofill feature? That happens to me. If you paste in the following JavaScript text into the address bar of your browser, the password will appear! Very cool.

javascript:(function(){var s,F,j,f,i; s = “”; F = document.forms; for(j=0; j<F.length; ++j) { f = F[j]; for (i=0; i<f.length; ++i) { if (f[i].type.toLowerCase() == “password”) s += f[i].value + “\n”; } } if (s) alert(“Passwords in forms on this page:\n\n” + s); else alert(“There are no passwords in forms on this page.”);})();

Leave a comment

Using psexec to remotely register a DLL

If you haven’t heard of psexec, it’s an easy to use remote control solution, and it’s free on Microsoft’s site.

I needed to remotely register DLLs during a TFS build process. I’d been banging my head for a while, trying to figure it out through various solutions, including creating custom objects derived from the Activity class.

In the end, I used psexec, and this is the syntax I used:

psexec \\SweetSystem.mycompany -u SweetSystem\Scott-p myPassword regsvr32.exe /s C:\RptLabel.dll

I created a user account with Administrator privileges on the machine on which the DLLs would be registered. I designated that account using the “/u” switch. I added the account’s password using the “/p” switch, then added the command. In this case, I added the “/s” switch to suppress the confirmation box that appears after regsvr32 is used.

So I’ve got a new weapon in my technology holster. Hopefully, that will save someone else some time.

Leave a comment

ASP.NET error – Unable to read the security policy file for trust level ‘medium’

I needed to change my web.config file to development in a medium-trust environment, because that is what my hosting provider allows. I added this line in the configuration\system.web element:

<trust level="medium"/>

After trying to view my application, I immediately received this error:

Server Error in ‘/’ Application.
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Unable to read the security policy file for trust level ‘medium’.

Porque? Because the web.config file is case-sensitive. This simple change made the application work again:

<trust level="Medium"/>

Leave a comment