Thursday, March 29, 2007

Blogger is integrated in Microsoft Office Word 2007

Writing blog posts in Microsoft Office Word 2007 is now much easier.

  1. Click on the Office button to select 'New'
  2. Select 'New Blog Post…'
  3. Configure your blog provider (in my case Blogger)

  4. After registrating the blog provider, you are able to publish posts on your blog !

Taskpanes: Moving, resizing and navigation

Have you ever had the idea to move your InfoPath 2003 taskpane to the bottom of your screen, to the left or the right?
A taskpane cannot be moved (in default cases), but by using customized Office code we can do it !

Move and resize task panes

using Microsoft.Office.Interop.InfoPath.SemiTrust;
using Microsoft.Office.Core;
using System.Reflection;

//The following function unwraps the CommandBars object so that the CommandBars object
//is easier to use in the code.
private CommandBars UnwrapCommandbarsObject(ObjectWrapper commandBarsWrapper)

//Get the System.Type object for the CommandBars wrapper object.
Type t = commandBarsWrapper.GetType().BaseType;

//Use the Type object to retrieve the InnerObject property of the wrapper.
CommandBars objCommandBars = (CommandBars)t.InvokeMember("InnerObject", BindingFlags.Public BindingFlags.NonPublic BindingFlags.Instance BindingFlags.GetProperty, null, commandBarsWrapper, null);

//Return the result.
return objCommandBars;

private void ButtonClickAction()
CommandBars objCommandBars = UnwrapCommandbarsObject( (ObjectWrapper) thisXDocument.View.Window.CommandBars);

CommandBar oCommandBar = objCommandBars["Task Pane"];
oCommandBar.Width = 600;


Navigate to website urls
HTMLTaskPane tp = (HTMLTaskPane)this.thisXDocument.View.Window.TaskPanes[0];
tp.Visible = true;

In InfoPath 2007 it would be:
HtmlTaskPane pane = (HtmlTaskPane)this.CurrentView.Window.TaskPanes[0];


  • You need full trust!
  • Add a reference to COM component -> Microsoft Office 11 Object Library


  • Changing the behaviour of your TaskPane at runtime, also effects InfoPath at design time !
    You can only undo the TaskPane customization by re-executing the reversed code.


Tuesday, March 06, 2007

How to Validate Arguments Of Public Methods? (Microsoft Design - CA1062)

FxCop can drive you crazy, but ... It improves the quality of your code!
Tip: enable the Code Analysis in the beginning!

I am sure that you have ever seen the following FxCop warning:
Microsoft.Design --> CA1062:ValidateArgumentsOfPublicMethods

This article gives you a uniform way of validating parameters!

1. Validating parameters in every public method
If you have to check every parameter every public method. This means that you add at least 3 lines ...

if( condition )
// exception statement;


  • Re-writing code every time you need to check parameters
  • 3 lines of code extra in every public method which has parameters.

2. Using the ParameterCheck class for Parameter validations
You can reduce the 3 lines of code into 1 line. Just make a separate Visual Studio Project which is responsable to check parameters. It is a static class which has static methods.

ParameterCheck Method Overview

  • NotNullOrEmpty
    Checks if a string is empty or null
  • NotNull
    Checks when an object is null. In case of a DateTime object, it cannot be the MinValue (which will be compared with null)
  • WithinRange (for int)
    Checks if the Int value (16/32/64 bit) has a value within the range (ranges inclusive)
  • WithinRange (for double)
    Checks if the decimal value (decimal, single, float, double) has a value within the range (ranges inclusive)
  • WithinRange (for DateTime)
    Checks if the DateTime value has a value within the range (ranges inclusive)
  • BiggerOrEquals (for int)
    Checks if a number has a value which is bigger or equals to the minimum value (minimum value included)
  • SmallerOrEquals (for int)
    Checks if a number has a value which is smaller or equals to the maximum value (maximum value included)

public static void NotNullOrEmpty(string parameterName, string parameterValue)
if (String.IsNullOrEmpty(parameterValue))
throw new ArgumentNullException(parameterName);


  • Just 1 line of code!
  • Reusability!
  • Same result

  • FxCop/Code Analysis does not recognize your class as being a valid parameter validation. You should add a SuppressMessage (right-click on the warning in the error list and select 'suppress message')

You can download the code of this article here.