Поделиться через


Now you see me, now you don't

My colleague Stephen Griffin recently blogged about how to show or hide the Sender Contact Photo feature in Outlook.  Since he only supplied the C++ version the product team asked me to supply the .NET version.  [Edit: 2/10/2014:  It has come to my attention that the code below will only work for Outlook 2010.  Support for this was removed in Outlook 2013.]

Visual Basic

 Public Sub SetSenderContactPhoto(ByVal Inspector As Object, ByVal ShowSenderContactPhoto As Boolean)
  Dim typeInspector As Type = Inspector.GetType()
  Dim dispidShowSenderPhotoMemberName As String = String.Format("[DispID={0}]", _ 
 &HF0D0)
  Dim args() As Object = {ShowSenderContactPhoto}
  Try
    typeInspector.InvokeMember(dispidShowSenderPhotoMemberName, _ 
        System.Reflection.BindingFlags.InvokeMethod, _
        Nothing, _
        Inspector, _
        args)
  Catch comEx As System.Runtime.InteropServices.COMException

  End Try
End Sub

 

C#

 void SetSenderContactPhoto(object Inspector, bool ShowSenderContactPhoto)
{
  Type typeInspector = Inspector.GetType();
  string dispidShowSenderPhotoMemberName = String.Format("[DispID={0}]", 0xF0D0);
  object[] args = {ShowSenderContactPhoto};

  try
  {
    typeInspector.InvokeMember(dispidShowSenderPhotoMemberName, 
        System.Reflection.BindingFlags.InvokeMethod,
        null,
        Inspector,
        args);
  }
  catch(System.Runtime.InteropServices.COMException comEx)
  {

  }
}