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: http://www.code4ward.net/main/RoyalTS/Download/StatisticandpreviousVersions.aspx

Enjoy!

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).

clip_image002

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

clip_image004 

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

Testing..1..2..3!

Image check…

1

Shorts - week 3, 2022

Post with links to what I am reading: 1. A very good post on different aspects of system architecture: https://lethain.com/introduction-to-a...