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

Sunday, 1 August 2010

WPF Commands

Q. What happens if we define both the Command for a button and also provide handler for its click event?

A. The click event's handler fires first, and then the command.

Q. Can we assign add a command twice to the CommandBindings collection with different execute event handler?

A. Through testing it looks only one execute handler is fired. The first binding which is added to the collection gets invoked.

Q. Can we do something additional when the built-in commands are fired? For example we want to do something more when a copy command is invoked. Adding a new binding for Application.Copy does not work. (refer previous question) Or if we can't extend can override the Application.Cut behavior?

Friday, 30 July 2010

Binding to ListData (with IsSynchronizedWithCurrentItem)

Today while testing out data binding in WPF to list controls, I learnt something new.

On the window, I created two list boxes, and a textblock control all have data context of an xml static resource.

For the ItemsSource in listbox I was using: {Binding XPath=@name} [the xml resource contains a Color element with attribute 'name]. I used IsSynchronizedWithCurrentItem on both the listboxes and bound the TextBlock Text to {Binding XPath=@Name}.

On testing the app I found, the controls are not synchronized. After referring to MSDN and some testing with different bindings - I found that to enable synchronization between all the controls to the CurrentItem of the collection, it is important to bind the list boxes to the whole collection. and not to a member or attribute (in this example).

So for listboxes it should be ItemsSource={Binding}, for display purposes we can use DisplayMemberPath or DataTemplate.


Friday, 16 July 2010

SlickRun custom magic words

[msdn]
Filename="http://www.google.com/search?hl=en&q=$W$ site:msdn.microsoft.com"
Notes="Searches MSDN using Google"
GUID={2F9AC37E-9BD9-486D-9168-D7C2FF0D0750}
StartMode=5
UseRunAs=0
Disable32BitRedir=0
[msdngo]
Filename="http://www.google.com/search?hl=en&btnI=I%27m+Feeling+Lucky&q=$W$ site:msdn.microsoft.com"
Notes="Goes to the first Google search item on MSDN site"
GUID={E82C1293-A5C3-4D18-BBD7-BAFC543AC6EE}
StartMode=5
UseRunAs=0
Disable32BitRedir=0
[n]
Filename="notepad.exe"
Params="$W$"
GUID={B3DADC2D-B5EA-4186-B165-CDCF7F6BEF2F}
StartMode=5
UseRunAs=0
Disable32BitRedir=0
[stack]
Filename="http://stackoverflow.com/"
GUID={28BF5F9B-CAE3-48E9-A66E-440135239B96}
StartMode=5
UseRunAs=0
Disable32BitRedir=0
[times]
Filename="http://www.nytimes.com"
Notes="The New York Times"
GUID={6791C0B1-91B9-4946-BC16-07B58AEFF9DF}
StartMode=5
UseRunAs=0
Disable32BitRedir=0
[wi]
Filename="http://frer0342:8080/WorkItemTracking/WorkItem.aspx?artifactMoniker=$W$"
GUID={592A1690-DA02-4F3B-8C17-EDAF6A4FBF24}
StartMode=5
UseRunAs=0
Disable32BitRedir=0
[wikipedia,encyc]
Filename="http://en.wikipedia.org/wiki/Special:Search?search=$W$&go=Go"
Notes="Search Wikipedia Online Encyclopedia"
GUID={7A4FFA2F-1DC7-4580-B235-70A21AC1C586}
StartMode=5
UseRunAs=0
Disable32BitRedir=0
[word]
Filename="winword.exe"
Notes="Microsoft Word text editing tool"
GUID={C1F88DA3-A72C-4244-832D-340512AB6BC6}
StartMode=5
UseRunAs=0
Disable32BitRedir=0

Thursday, 15 July 2010

Dev Tools


- Slickrun: http://www.fiddlertool.com/SlickRun/

- Process explorer: http://technet.microsoft.com/fr-fr/sysinternals/bb896653.aspx



(Code snippet execution)


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