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