Tuesday, August 5, 2008

Visual Studio 2005 Tools for Office, CommandBarButton FaceId Property

From http://www.kebabshopblues.co.uk/2007/01/04/visual-studio-2005-tools-for-office-commandbarbutton-faceid-property/
I recently started experimenting with Visual Studio 2005 and Visual Studio Tools for Office (VSTO) 2003. This entry is a technical .Net / VS2005 / VSTO blog and will probably not be of interest unless you use these tools yourself.

Yuck. Office applications allow many configuration / add-in options programmatically which are quite impressive, but do not sit well with other .Net development tools. For example, in Forms development, if we want to create a Button on a form programmatically, we declare a new Button(). In VSTO, we declare a new CommandBar, and then have to use the CommandBar.Add() method to create a new button on that toolbar.

One of the first things that I wanted to achieve - after adding a basic toolbar to Outlook 2003, was to add buttons with icons. It was frustrating that this was a topic that seemed to be omitted from the book ‘Visual Studio Tools for Office: Using C# with Excel, Word, Outlook, and Infopath’ (Carter and Lippert), and it almost entirely eluded me as to how to do it. There was the CommandBarButton.FaceId property, useful if you wanted a preset icon on your button (but no apparent documentation of what numbers should be used for which icons). Then there were the Picture and Mask properties that appeared to have relevance to this task, but I could not fathom how to use them. Web searches demonstrated some approaches, even on MSDN, that required the use of the clipboard to load an image; something that could muck up the user’s clipboard and therefore highly undesirable, it seemed to me.

Anyway, I finally found what I needed, on MSDN itself. This was one occasion when a generic web search with Google did not outperform Microsoft’s own site (prior poor recommendations that I had found turned out to refer to previous versions of .Net or VSTO).

But still in all my searches I failed to find documentation of the simplest way of assigning an icon to a button or menu entry, using the FaceId property. Possibly, I missed it; that would be easy in amongst the morass of documentation.

This blog documents the numbers and associated icons as discovered from using the various FaceId numbers in Outlook. I have not yet cross-checked the icon numbering with different applications. Lower down this page, I’ll comment briefly on how I got these images later in the document.

The Icons

The number to the right of the icon is the appropriate FaceId to use:

0000-0099

0100-0199

0200-0299

0300-0399

0400-0499

0500-0599

0600-0699

0700-0799

0800-0899

0900-0999

1000-1099

1100-1199

1200-1299

1300-1399

1400-1499

1500-1599

1600-1699

1700-1799

1800-1899

1900-1999

2000-2099

2100-2199

2200-2299

2300-2399

2400-2499

2500-2599

2600-2699

2700-2799

2800-2899

2900-2999

How I Made These Images

MSDN Support had a very tempting page which refers to ‘Finding FaceID Numbers for Your Microsoft Office 97 Toolbars’; but that text is not linked and does not retrieve anything on a search; though the text suggests that it (should have been) a tool to provide documentation of these FaceId’s in an Excel spreadsheet. Tempting, therefore, but fruitless (even if it referred to past versions, perhaps it might have helped?)

So, I wrote a little piece of code to create an Outlook toolbar with 104 buttons (the first 4 buttons being repeated, so there were 100 unique faceId’s), each with a FaceId and a text caption of the number used to achieve the icon. Making the Outlook window very narrow (so only the first four buttons were displayed) meant that clicking on the toolbar expansion button gave a drop-down with 100 unique buttons on. A bit of jiggery pokery with a screen-shot gave the necessary images. It was a pain to be such a manual process, but there you go; sometimes these things can’t be helped… I did decide to stop at 2999 though ;)

Maybe my OCD will cut in soon though and compel me to find the last icon…

[Added 24/1/07: I have now added a post with FaceId’s 3000 - 3999 for your enjoyment.]

Tuesday, July 29, 2008

Outlook Programming: how to find the parent message for a reply or forward message.

I'm currently involved in developing Outlook add-in. During that I've faced the problem how to find the parent message for a reply or forward message. The idea is that all messages in a conversation have the same ConversationTopic value, while the ConversationIndex is increased by 5 bytes with each change. Here is the sample that uses a MailItem named lastMailItem and searches the Inbox for a matching parent item.


MAPIFolder inbox = m_applicationObject.Session.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
Items inboxItems = inbox.Items.Restrict("[ConversationTopic] = " + "\"" + m_lastMailItem.ConversationTopic + "\"");

string str = m_lastMailItem.ConversationIndex;
string convIndex = str.Substring(0, str.Length - 10);
foreach (MailItem item in inboxItems)
{
if (item.ConversationIndex == convIndex)
{
// Item is found, add your code here!!
break;
}
}

Hope this will help you lot's.

Resolving the issue of those using MSN Messenger (Error Code: 80072745)

A lot of people are experiencing problems with MSN Messenger, especially the latest version. MSN Messenger 8, also known as Messenger Live!
I expeirienced this problem myself, relating to Error Code: 80072745. It was a pain in the ass, it became rather annoying that I could not sign in.
I kept getting the following message “We were unable to sign you in to the MSN Messenger, possibly because of a problem with your Internet connection. Please try again later. 80072745″
I began to try signing in to an online messenger service, such as http://webmessenger.msn.com, I was able to sign in fine, so blaming the server was out of the question.
If you are experiencing this problem, I sugest you try the following steps.

In my personal case the problem was is Eset NOD32 Antivirus, and I simply removed MSN from it's Web access protection list.

(Before you do the following steps, be sure that your Anti-Virus is fully updated, and you have run a full system scan for viruses/trojans.)
1: If you are using a Firewall, be sure that MSN Messenger has been granted access.
2: Clear your Internet Explorer’s Cache and Cookies. — Open Internet Explorer, click on Tools>Options. Delete Files and Delete Cookies. (If you are using something different, Mozilla Firefox, they can be found in the Privacy TAB).
3: MSN Messenger is required for “Use SSL 2.0″ and “Use SSL 3.0″ are enabled. — Open Internet Explorer, click on Tools>Options. Go to Advanced, scroll down and check them both.
4: Final step, Go to Start>Run and type in cmd and press enter. Then enter the commands below one by one, and then press enter for each command:regsvr32 softpub.dll( A message will appear, click ok. Then type in the next command, and repeat)regsvr32 wintrust.dllregsvr32 initpki.dllregsvr32 MSXML3.dll
After doing this, restart your Modem/Router, then try to sign in. If you are still unable to sign in, restart your computer.
Sometimes spyware/addware can be the problem, I recommend that you use Spybot - Search and Destroy. Click here for the Spybot website.
If you need any more information, feel free to contact me. martin@martinjknight.com
Please note that this information was taken from a well known source and was not created by me.
Here is another way of possibly resolving the problem, which was posted by internet-kaltersia. You may want to try this out if the previous information didn’t work.
Here is the crazy thing I had to do to fix this…
Quote from Raphael
Dear all if you have not heard simply add these addresses to the following file that should be opened with notepad and MSN will work.
C:\WINDOWS\system32\drivers\etc\hosts - (When you open the ETC folder open the HOSTS file using notepad).
insert the following addresses:65.54.239.80 messenger.hotmail.com65.54.239.80 dp.msnmessenger.skadns.net
(INSERT THEM DIRECTLY UNDER THE OTHER 2 ADDRESSES AND ALIGN THEM WITH TAB.)
Easy done … good luck.
Thank you for that additional information!

Please note that this information was taken from a well known source and was not created by me.

Monday, July 7, 2008

How to check for hidden/system files and folders.

Hi,

Maybe not everybody knows how to check whether file or folder is hidden/system.
This code returns array of FileInfo and DirectoryInfo objects.

FileInfo[] info = dirInfo.GetFiles();
DirectoryInfo[] dirs = dirInfo.GetDirectories();

They both have Attributes property which is flag enum. So you can use this property to check for files attributes. Here is sample method to check whether object has hidden or system attributes:

private static bool IsNotHiddenOrSystem(FileAttributes attributes)
{
return (attributes & (FileAttributes.Hidden FileAttributes.System)) == 0;
}

Full list of file attributes can be found on MSDN site:
http://msdn.microsoft.com/en-us/library/system.io.fileattributes.aspx

Enjoy ;)

Saturday, July 5, 2008

DynamicControlsPlaceholder - A placeholder that saves its child controls

Problem:

ASP.NET gives a developer the opportunity to programmatically add controls to a web form using ParentControl.Controls.Add(new Control());
However, these controls are not persisted in any way thus having to be recreated for each subsequent request.

Goal:

To create a control that behaves like a placeholder but additionally handles recreating dynamic controls on subsequent requests.

Procedure:

I have created a custom control called DynamicControlsPlaceholder that derives from Placeholder and overrides Load- and SaveViewState.
In SaveViewState, the control hierarchy is recursively traversed and the control type and ID persisted to a string
In LoadViewState the persisted information is used to recreate the control tree to the state before.

Download (V2.2):

From: http://www.denisbauer.com/ASPNETControls/DynamicControlsPlaceholder.aspx

Friday, July 4, 2008

What's the difference between Bind and Eval

Data-binding expressions are contained within <%# and %> delimiters and use the Eval and Bind functions. The Eval function is used to define one-way (read-only) binding. The Bind function is used for two-way (updatable) binding. In addition to calling Eval and Bind methods to perform data binding in a data-binding expression, you can call any publicly scoped code within the <%# and %> delimiters to execute that code and return a value during page processing.
Data-binding expressions are resolved when the DataBind method of a control or of the Page class is called. For controls such as the GridView, DetailsView, and FormView controls, data-binding expressions are resolved automatically during the control's PreRender event and you are not required to call the DataBind method explicitly.
Using the Eval Method
The Eval method evaluates late-bound data expressions in the templates of data-bound controls such as the GridView, DetailsView, and FormView controls. At run time, the Eval method calls the Eval method of the DataBinder object, referencing the current data item of the naming container. The naming container is generally the smallest part of the data-bound control that contains a whole record, such as a row in a GridView control. You can therefore use the Eval method only for binding inside templates of a data-bound control.
The Eval method takes the name of a data field and returns a string containing the value of that field from the current record in the data source. You can supply an optional second parameter to specify a format for the returned string. The string format parameter uses the syntax defined for the Format method of the String class.

Using the Bind Method
The Bind method has some similarities to the Eval method, but there are significant differences. Although you can retrieve the values of data-bound fields with the Bind method, as you can with the Eval method, the Bind method is also used when data can be modified.
In ASP.NET, data-bound controls such as the GridView, DetailsView, and FormView controls can automatically use the update, delete, and insert operations of a data source control. For example, if you have defined SQL Select, Insert, Delete, and Update statements for your data source control, using Bind in a GridView, DetailsView, or FormView control template enables the control to extract values from child controls in the template and pass them to the data source control. The data source control in turn performs the appropriate command for the database. For this reason, the Bind function is used inside the EditItemTemplate or InsertItemTemplate of a data-bound control.
The Bind method is typically used with input controls such as the TextBox control rendered by a GridView row in edit mode. When the data-bound control creates these input controls as part of its own rendering, it can extract the input values.
The Bind method takes the name of a data field to associate with the bound property.

Wednesday, July 2, 2008

More information about ASP.NET Page life-cycle and common events

I’ve found wonderful document about ASP.NET Page lifecycle events on http://john-sheehan.com/blog. Little information about general page Life-cycle stages and events:
life

The whole document can be found here: http://john-sheehan.com/blog/wp-content/uploads/aspnet-life-cycles-events.pdf . There is also information about Data Binding Events for Data-Bound Controls and Common Life-cycle Events.

Enjoy :)