Thursday, 28 October 2010

Internet explorer has restricted this webpage from running scripts...

When we open an XML file from local computer, I get the following error message:
"In order to protect your security, Internet explorer has restricted this webpage from running scripts or ActiveX controls that could access your computer"

Which could be quite irritating if it is a large document or if you use the '+' often.

Solution: To resolve this go to Tools>Internet Options>Advanced and check the following:
Allow active content to run files in my Computer Allow active content from CDs to run on my Computer.

Royal TS - remote desktop tool

I had been using RDC available in Windows for a long time and didn't actually found a problem with it until the day when I had to connect to half a dozen virtual machines - all of them having long, hard to remember auto generated passwords.

Enter Royal TS. It's just the first day of using it and I am already thanking my stars. (Got to know about this tool just by chance on of the manager's computer).

The current version are shareware with limited features, but the version 1.5 is full featured free version:


Tuesday, 12 October 2010

LINQ – fetching controls on the WinForm

Let us take a simple example, but a useful one. We start with a form, having 3 text boxes and a button. The button validates whether all the text boxes are filled up or not (a common business case).


We want to color background of the textboxes Red if they are empty:


var textBoxes = from tBox in this.Controls.OfType<TextBox>()
      where tBox.Text.Trim() == ""
      select tBox;
foreach (TextBox tbox in textBoxes)
    tbox.BackColor = Color.Red;

We get the same result as before. Building upon this, right now we get all the text boxes but what if we want to check only the visible text boxes? We should be able to achieve it by adding ‘tBox.Visible == true’ in the LINQ query. Which brings us to the question, how do we add AND condition in LINQ? (along the way let’s add Enabled condition as well)

var textBoxes =
  from tBox in this.Controls.OfType<TextBox>()
  where tBox.Text.Trim() == "" && 
  tBox.Visible == true && 
  tBox.Enabled == true
  select tBox;

For testing the OR condition, we select not just text boxes but Combo Boxes as well.

var controls =
  from Control ctl in this.Controls
  where (ctl is TextBox || ctl is ComboBox) &&
  (ctl.Text.Trim() == "" && ctl.Visible == true && ctl.Enabled == true)
  select ctl;

Checking from Live writer


Image check…


C# Reactive Extensions - Buffer and Window

I was going through Buffer and Window in RX, thought a few examples would help clear the differences. First create a buffer of even numbe...