Programmatically display UDF in Outlook Folder


Joined
May 3, 2010
Messages
2
Reaction score
0
Is there a way to display a User Defined Field programmatically in an Outlook Folder?.

Here's how I create it (VB2008 and VSTO3):

usrProp = m_Item.UserProperties.Add(strPropName, Outlook.OlUserPropertyType.olText, True, Outlook.OlUserPropertyType.olText)
usrProp.Value = oValue
m_Item.Save()

After this statement the Property does show up in the list of UDF's when I click on Column Header, Customize, Fields, but how can I add it programmatically to the folder view?
 
Ad

Advertisements

Joined
May 3, 2010
Messages
2
Reaction score
0
Never mind, I think I found a solution. It's closely based on this post: http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/30ca71bf-b60c-4ed1-85de-0aa739f5ddd1

Here's my subroutine to add the custom field to the current view:

Private Sub AddColumnToView(ByVal strField As String)
Dim ns As Outlook.NameSpace
Dim fld As Outlook.Folder
Dim vw As Outlook.TableView
Dim vwf As Outlook.ViewField
Dim udf As Outlook.UserDefinedProperty
Dim udfName As String

ns = Globals.ThisAddIn.Application.Session
fld = TryCast(m_Item.Parent, Outlook.Folder) 'm_Item represents current MailItem
If fld Is Nothing Then
fld = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
End If
vw = fld.CurrentView


udf = fld.UserDefinedProperties.Find(strField)
If udf Is Nothing Then
udf = fld.UserDefinedProperties.Add(strField, Outlook.OlUserPropertyType.olText, _
Outlook.OlFormatText.olFormatTextText, "")

udfName = _
"http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/" & strField.Replace(" ", "%20")
vwf = vw.ViewFields.Insert(udfName, vw.ViewFields.Count)
Else
Try
vwf = vw.ViewFields(udf.Name)
Catch ex As System.Runtime.InteropServices.COMException
End Try

If vwf Is Nothing Then
vwf = vw.ViewFields.Insert(udf.Name, 2)
vwf.ColumnFormat.Width = 30
vw.Save()
vw.Apply()

End If
End If




End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top