bhodso
Posts: 6
Joined: 2013-01-14
|
I have created a user defined column value and associated it to a mail object in Outlook using code similar to this:
var prop = mailItem.UserProperties.Find("inteum", true);
if (prop == null)
{
prop = mailItem.UserProperties.Add("inteum", Outlook.OlUserPropertyType.olText);
prop.Value = dlgDropAction.SelectedRemarkFk.ToString();
}
else
{
prop.Value = dlgDropAction.SelectedRemarkFk.ToString();
}
I know I can right-click on the Outlook column headers and show the column but I want to know how to do this programmatically. How can I via code, add this User Property and show it in the visible columns automatically like the screenshot shown here:
|
|
Andrei Smolin
Add-in Express team
Posts: 19122
Joined: 2006-05-11
|
|
bhodso
Posts: 6
Joined: 2013-01-14
|
The way I solved this (based on your tips above) was first getting the current folder that was selected like this:
// get explorer instance
Outlook.Explorer explorerInstance = explorer as Outlook.Explorer;
// get current folder
Outlook.MAPIFolder folder = null;
folder = explorerInstance.CurrentFolder;
// make sure folder is a tableView
if (folder != null && folder.CurrentView.ViewType == Outlook.OlViewType.olTableView)
{
}
After I got the folder and made sure it is a tableview type, I checked if there are any mail items in it:
if (folder.Items != null && folder.Items.Count > 0)
{
if (folder.Items[1] is Outlook._MailItem)
{
mailItem = folder.Items[1] as Outlook._MailItem;
// now I add the property to this mail Item if it has not already been added using code similar to this:
// SEE link at bottom of post
// finally I set the current view of the folder to show this new column
tableView = folder.CurrentView as Outlook.TableView;
viewField = tableView.ViewFields.Add("Exact Property Name I Added to MailItem above");
columnFormat = viewField.ColumnFormat;
columnFormat.Align = Outlook.OlAlign.olAlignLeft;
columnFormat.Width = 10;
tableView.Save();
tableView.Apply();
}
}
Here is the link that shows how to add a property to a mailItem:
http://www.add-in-express.com/creating-addins-blog/2011/08/19/how-to-add-a-custom-property-to-the-userproperties-collection-of-an-e-mail-item-in-outlook/ |
|
Andrei Smolin
Add-in Express team
Posts: 19122
Joined: 2006-05-11
|
Many thanks for sharing the solution with forum readers!
Andrei Smolin
Add-in Express Team Leader |
|