none
How to display Outlook inbox within a Winform (VS 2008-C#) ?

    Întrebare

  • I have an old VB application that opens Outlook, displays the Inbox and allows users to click on a message.  There is a button that starts an upload of the email and any attachments to a binary file which is then converted to a TIFF/image file..  It uses MODI which appears to cause problems on Windows 7.   The whole process is a little buggy and we are attempting to re-write the Outlook module and add modules to open uploaded documents as Word, Excel, PDFs.  The company is in a process of upgrading our Office from 2003 to 2010 but it’s going to take a while and we will need to support both versions.Requirements:

           Must work on Windows 7 (32 bit) and XP 

           Must work with different versions of Office (2003/2010)

           Would like to write it in C#

           Would like to be able to eventually use code on a future web app, if possible

           Do not want to use 3-rd party controls although we do have a Infragisitics Winforms license and already use some of their controls in this app.

    I’m looking for a clear tutorial on how to display the Outlook Inbox within a folder.  I’ve found a lot of old code and don’t know what is out-of-date and have yet to get anything to work.  I don’t want to use old code and then find out it doesn’t work on Windows 7 and/or Office 2010. I have a reference to the 'Microsoft Outlook View Control'  on my form/usercontrol and code.  I found an example that uses ‘AXMicrosoft.Office.Interop.OutlookViewCtl' but the Microsoft Outlook View control doesn't seem to work using that code as an example.  What is the difference between the Microsoft Outlook View Control and the AXMicrosoft.Office.Interop.OutlookViewCtl?   

    I have code that can loop thru the Inbox mail but don't know how to display the inbox within the control.  How do I use it to display the Outlook inbox?  Can I use the Outlook View Control to display Outlook just like you see if when you open Outlook from your desktop? 

    I don't have a lot of C# or COM expericence so I really need some clear and complete instructions, please.   Please....

    Thanks!

    28 februarie 2012 13:09

Toate mesajele

  • Hi Retrain,

    Thanks for posting in the MSDN Forum.

    It's based on my experience that we aren't able to develop a window form application which can cover Outlook 2003, Outlook 2007 and Outlook 2010. It might work if you use Outlook 2007's PIA in your window form application and use Outlook 2010 on you computer.

    Would you please tell me which part of mail item you want to convert to TIFF image?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    29 februarie 2012 05:34
  •  The company is moving to Office 2010 so we would go with 2010 if we can only get one version to work.  Thanks very much for the information about the different versions because I wasn't sure if it would work with multiple version.

    The application currently allows the users to click on an email and the process is using MODI to convert the email and any attachments to a tiff file.  From the information that I've found, MODI is not supported on Windows 7 so we are going to rewrite any MODI code.  The new process should be able to save the email as an '.msg' file.  Any attachments should also be saved as '.doc' or '.xls'.  The only files that will be tiff will be the existing tiff documents in the database.     

    I was able to get the code to connect to Outlook 2003 with the code snippet below but don't know how to 'hook' it up to the Outlook View Control so it can be viewed on a winform.

    Thanks for any help!

    29 februarie 2012 20:16
  • using Outlook = Microsoft.Office.Interop.Outlook;
    private OutlookApp.NameSpace outlookNameSpace = null;
    private OutlookApp.Application app = null;
    private OutlookApp.MAPIFolder inbox = null;
    private OutlookApp.Items items = null;
    private OutlookApp.MailItem mail = null; 
    public void SetupOutLookView()
    { // http://msdn.microsoft.com/en-us/library/ms268998%28v=vs.90%29.aspx
      try
      {
        app = new OutlookApp.Application();
        outlookNameSpace = app.GetNamespace("MAPI");
        inbox = outlookNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
        items = inbox.Items;
        // Sort those items by date or it's a confusing jumble of emails
        items.Sort("SentOn", true);
        //Loop thru the inbox and display the subject and date
        for (int i = 1; i <= 3; i++)
        {
           mail = (Outlook.MailItem)items[i];
           MessageBox.Show("Items: " + mail.Subject.ToString() + " Date: " + mail.SentOn.ToString());
        }
     }
     catch (System.Runtime.InteropServices.COMException ex)
     {
       MessageBox.Show(ex.ToString());
     }
     finally
     {
       outlookNameSpace = null;
       app = null;
       inbox = null;
       items = null;
       mail = null;
     }

    29 februarie 2012 20:18
  • Hi Retrain,

    If you goal is save Outlook Mail Item to msg file the following snippet will work. In this snippet I use MD5 digest as the msg file's name.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Outlook = Microsoft.Office.Interop.Outlook;
    using System.Runtime.InteropServices;
    using System.Diagnostics;
    using System.Security.Cryptography;
    
    namespace OutlookSaveAs
    {
        public partial class Form1 : Form
        {
            private Outlook.Application OlApp = null;
            private List<Outlook.MailItem> list = null;
            private DateTime diedDate = DateTime.Now;
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                Process[] ps = Process.GetProcessesByName("OUTLOOK");
                if (ps.Length > 0)
                {
                    OlApp = (Outlook.Application)Marshal.GetActiveObject("Outlook.Application");
                }
                else
                {
                    OlApp = new Outlook.Application();
                }
                listView1.Items.Clear();
                list = new List<Outlook.MailItem>();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                FolderBrowserDialog fbd = new FolderBrowserDialog();
                fbd.ShowDialog();
                label2.Text = fbd.SelectedPath;
            }
    
            private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
            {
                diedDate = dateTimePicker1.Value;
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                if (OlApp != null)
                {
                    Outlook.NameSpace session = OlApp.Session;
                    Outlook.MAPIFolder Inbox = session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
                    string Filter = string.Format("[ReceivedTime] <= '{0}'", diedDate.ToShortDateString());
                    Outlook.Items Items = Inbox.Items.Restrict(Filter);
                    foreach (object obj in Items)
                    {
                        if (obj is Outlook.MailItem)
                        {
                            Outlook.MailItem Item = (Outlook.MailItem)obj;
                            list.Add(Item);
                            listView1.Items.Add(Item.Subject);
                        }
                    }
                    progressBar1.Minimum = 0;
                    progressBar1.Maximum = Items.Count;
                }
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                if (label2.Text.Length > 0)
                {
                    int b = list.Count - 1;
                    for(int i = 0; i <= b;i++)
                    {
                        Outlook.MailItem item = list[b - i];
                        using (MD5 md5Hash = MD5.Create())
                        {
                            byte[] buffer = md5Hash.ComputeHash(Encoding.UTF8
                            .GetBytes(item.Subject +"||"+ item.ReceivedTime.ToLongDateString()));
                            StringBuilder builder = new StringBuilder();
                            for (int j = 0; j < buffer.Length; j++)
                            {
                                builder.Append(buffer[j].ToString("x2"));
                            }
                            item.SaveAs(label2.Text + "\\" + builder.ToString() + ".msg", Outlook.OlSaveAsType.olMSGUnicode);
                            listView1.Items[b - i].Remove();
                        }
                        progressBar1.Value = i+1;
                    }
                    list.Clear();
                }
            }
        }
    }

    And I don't thing you need save the attachment to hard disk again due to msg file will include it.

    I hope it can help you.


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    1 martie 2012 03:04
  • Hi Retrain,

    Any Update?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    5 martie 2012 02:13
  • Hi Tom,

    I'm gonna give it a try today and I'll let you know how it goes.  I really appreciate your help!

    5 martie 2012 13:28
  • hy people,

    i would like to search Inbox in my Outlook.pst , but procedure return me only mails from a time when i actully instal outlook on my computer.here is code below.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Microsoft.Office.Interop.Outlook;
    using Outlook = Microsoft.Office.Interop.Outlook;


    namespace WindowsFormsApplication2
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void Form1_Load(object sender, EventArgs e)
            {

            }
            Microsoft.Office.Interop.Outlook.Application Application = new Microsoft.Office.Interop.Outlook.Application();
            Outlook.NameSpace outlookNameSpace;
            Outlook.MAPIFolder inbox;
            Outlook.Items items;

            private void button1_Click(object sender, EventArgs e)
            {
                outlookNameSpace = this.Application.GetNamespace("MAPI");
                outlookNameSpace.Logon(null, null, false, false);

                inbox = outlookNameSpace.GetDefaultFolder( Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);

    for (int counter = 1; counter <= inbox.Items.Count; counter++)
                {
                    Microsoft.Office.Interop.Outlook.MailItem item = (Microsoft.Office.Interop.Outlook.MailItem)inbox.Items[counter];
                    MessageBox.Show(item.ReceivedTime.ToString() );
                }

    it not show me items on-line..The last one..Shows me from earlier date-i found that is a date when i installl outlook on my Computer.Is tih problem with configurin outloook, computer, code?? HELP, PLEASE

    5 martie 2012 13:39
  • Tom,

    I tried your code but I still have several problems.

    1.  The GetProcessesByName found Outlook but the Marshal.GetActiveObject line returns a null.  When I comment out that part of the code and just leave olAPP = new Outlook.Application, I am able to get a reference to Outlook.

                Process[] ps = Process.GetProcessesByName("OUTLOOK");
               
    if (ps.Length > 0)
               
    {
                   
    OlApp = (Outlook.Application)Marshal.GetActiveObject("Outlook.Application");
               
    }
               
    else
               
    {
                   
    OlApp = new Outlook.Application();
               
    }

    2.   Need to display the actual Inbox:  e button3_Click event to populate the listbox but what I really need is to display the Inbox folder.  The old VB application uses AxOLXLib.AxViewCtl (AxViewCtlOutlook As AxOLXLib.AxViewCtl) to display the inbox but I can't figure out how to implement it in my C# app on Windows 7.  I need to display the Inbox (and allow the users to select other Outlook folders) so the users can select one or more emails to upload to the database. 

    3.  System.Windows.Froms.AxHost.InvalidActiveXStateException:  properties are different in the new C# app.  I can't even find a AxViewCtlOutlook.Enabled  property.  In the debugger,all the AxViewCtlOutlook  properties are throwing an System.Windows.Froms.AxHost.InvalidActiveXStateException.  What am I missing that is causing the exception?

    OLD VB CODE:

    If Not Me.AxViewCtlOutlook Is Nothing Then Me.AxViewCtlOutlook.Dispose()

    Me.AxViewCtlOutlook = New AxOLXLib.AxViewCtl

    Me.ugbxInboxView.Controls.Add(Me.AxViewCtlOutlook)

    Me.AxViewCtlOutlook.ContainingControl = Me

    Me.AxViewCtlOutlook.Dock = System.Windows.Forms.DockStyle.Fill

    Me.AxViewCtlOutlook.Enabled = True

    Me.AxViewCtlOutlook.Location = New System.Drawing.Point(3, 6)

    Me.AxViewCtlOutlook.Name = "AxViewCtlOutlook"

    Me.AxViewCtlOutlook.Size = New System.Drawing.Size(1069, 0)

    Me.AxViewCtlOutlook.TabIndex = 0

    How do I display the actual Inbox folder within the Winform without manually looping thru and displaying each MailItem?  ?  And can you recommend a good book for coding Microsoft Office in a winforms app, please?

    Thanks!

    5 martie 2012 20:57
  • Hi Retrain,

    I think this snippet will fit you. This application's speed will faster than use Outlook View Control.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    using System.Diagnostics;
    using Outlook = Microsoft.Office.Interop.Outlook;
    using System.Security.Cryptography;
    
    namespace WindowsOutlookIssue
    {
        public partial class Form1 : Form
        {
            private Outlook.Application OlApp = null;
            private Outlook.MAPIFolder OlInbox = null;
            private string SavePath = null;
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                Process[] ps = Process.GetProcessesByName("OUTLOOK");
                if (ps.Length > 0)
                {
                    OlApp = Marshal.GetActiveObject("Outlook.Application") as 
                        Outlook.Application;
                }
                else
                {
                    OlApp = new Outlook.Application();
                }
                if (OlApp != null)
                {
                    Outlook.NameSpace OlSession = OlApp.Session;
                    Outlook.OlDefaultFolders d = Outlook.OlDefaultFolders
                        .olFolderInbox;
                    OlInbox = OlSession.GetDefaultFolder(d);
                    TreeNode root = new TreeNode("Inbox");
                    treeView1.Nodes.Add(root);
                    IterateInbox(OlInbox, root);
                    treeView1.ExpandAll();
                    ListMails(OlInbox);
                }
            }
    
            private void Form1_FormClosed(object sender, FormClosedEventArgs e)
            {
                if (OlApp != null)
                    Marshal.ReleaseComObject(OlApp);
            }
    
            private void IterateInbox(Outlook.MAPIFolder folder, TreeNode root)
            {
                if (folder.Folders.Count > 0)
                {
                    foreach (Outlook.MAPIFolder f in folder.Folders)
                    {
                        TreeNode child = new TreeNode(f.Name);
                        root.Nodes.Add(child);
                        IterateInbox(f, child);
                    }
                }
            }
    
            private void treeView1_NodeMouseClick(object sender, 
                TreeNodeMouseClickEventArgs e)
            {
                Outlook.MAPIFolder currentFolder = GetCurrentFolder(e.Node
                    .FullPath);
                ListMails(currentFolder);
            }
    
            private Outlook.MAPIFolder GetCurrentFolder(string Path)
            {
                Outlook.MAPIFolder result = null;
                string[] list = Path.Split('\\');
                if (list.Length == 1)
                    result = OlInbox;
                if (list.Length > 1)
                {
                    Outlook.MAPIFolder temp = null;
                    result = OlInbox;
                    for (int i = 1; i < list.Length; i++)
                    {
                        temp = result.Folders[list[i]];
                        result = temp;
                    }
                }
                return result;
            }
    
            private void ListMails(Outlook.MAPIFolder folder)
            {
                listView1.Items.Clear();
                string labe = "/" + folder.Items.Count.ToString();
                for (int i = 1; i <= folder.Items.Count; i++)
                {
                    var obj = folder.Items[i];
                    if (obj is Outlook.MailItem)
                    {
                        Outlook.MailItem mail = (Outlook.MailItem)obj;
                        ListViewItem li = new ListViewItem(mail.ReceivedTime
                            .ToLongDateString());
                        li.SubItems.Add(mail.Subject);
                        li.SubItems.Add(mail.EntryID);
                        listView1.Items.Add(li);
                    }
                    Text = i.ToString() + labe;
                }
            }
    
            private void sToolStripMenuItem_Click(object sender, EventArgs e)
            {
                FolderBrowserDialog fbd = new FolderBrowserDialog();
                fbd.ShowDialog();
                SavePath = fbd.SelectedPath;
            }
    
            private void saveCurrentItemToolStripMenuItem_Click(object sender,
                EventArgs e)
            {
                if (SavePath != null)
                {
                    if (listView1.SelectedItems.Count != 1)
                    {
                        MessageBox.Show("Please select only one item");
                    }
                    else
                    {
                        string EntryID = listView1.SelectedItems[0].SubItems[2]
                            .Text;
                        Outlook.MailItem mail = OlApp.Session
                            .GetItemFromID(EntryID);
                        if (mail != null)
                        {
                            mail.SaveAs(SavePath + "\\"
                                + FileNameMaker(mail.ReceivedTime, mail.Subject)
                                + ".msg", Outlook.OlSaveAsType.olMSGUnicode);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Please set Save Path first!");
                }
            }
    
            private string FileNameMaker(DateTime received, String subject)
            {
                string result = null;
                using (MD5 md5Hash = MD5.Create())
                {
                    byte[] buffer = md5Hash.ComputeHash(Encoding.UTF8
                    .GetBytes(subject + "||" + received.ToLongDateString()));
                    StringBuilder builder = new StringBuilder();
                    for (int j = 0; j < buffer.Length; j++)
                    {
                        builder.Append(buffer[j].ToString("x2"));
                    }
                    result = builder.ToString();
                }
                return result;
            }
    
            private void saveAllItemsToolStripMenuItem_Click(object sender,
                EventArgs e)
            {
                if (SavePath != null)
                {
                    foreach (ListViewItem li in listView1.Items)
                    {
                        string EntryID = li.SubItems[2].Text;
                        Outlook.MailItem mail = OlApp.Session
                            .GetItemFromID(EntryID);
                        if (mail != null)
                        {
                            mail.SaveAs(SavePath + "\\"
                                + FileNameMaker(mail.ReceivedTime, mail.Subject)
                                + ".msg", Outlook.OlSaveAsType.olMSGUnicode);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Please set Save Path first!");
                }
            }
        }
    }

    And the code I written in the Form1_Load method is used to get a current Outlook instance. It can let me do my issue without affect my Outlook. I never get null value if my Outlook has been run. It doesn't necessary, take it easy.

    I hope it can help you.

    @Baturanija,

    Thanks for posting in the MSDN Forum.

    I think it will make more sense if you create a new thread to post your issue. New thread will let your issue easier to retrieve and more community members will take care of it.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    6 martie 2012 03:02
  • Hi Tom,

    Thanks for the code!  I've been playing with it all day.  Here's my current issues/questions.

    1.  The Marshal.GetActiveObject was throwing a Com exception unless I opened Outlook before running the code.  I added a try/catch for the ComException and, if there is an exception, I added code to create the 'OlApp = new Outlook.Application()' in the Catch block.  Am I violating any 'rules' by adding it there?

    2.  The IterateInbox method does not add anything to the treeview or throw an error.  The 'folder.Folders.Count' is actually 0.  I'm not sure whwat it was supposed to be showing.  Is there something wrong with it?

    3.    The saveCurrentItemToolStripMenuItem_Click and the saveAllItemsToolStripMenuItem_click events would not compile with an error on the GetItemFromId.  I changed the code in both events to add the StoreId to the GetItemFromId as follows below.  Is that correct?  I haven't had time to test the actual code but needed to make the change to get the app to build.

            Outlook.MAPI.Folder currentFoler = null;

            currentFolder - GetCurrentFolder(treevView1.SelectedNode.FullPath);

            Outlook.MailItem mail = (Outlook.MailItem)OLApp.Session.GetItemFromId(EntryID, currentFolder.StoreID);

    4.   If I click on an email listing in the listView1 control, how do I open the actual email?

    5.  I still want to get the ActiveX control to display the inbox.  The existing app uses an ActiveX control and we want the new version to look as similar as possible. Using the ActiveX control should keep the same look and feel of the existing visual component.  I'll check the performance between the code that you gave me and the ActiveX control once I get them both to work.  So how do I use the Microsoft Office Outlook View Control?  Is there a reason (other than performance) that I should not use the Microsoft Office Outlook view  control ?

    Thanks for all of your help!

    6 martie 2012 21:20
  • Hi Retrain,

    I'm not sure about what happened on you side. So I dieced share my project with you. Please try my project to see wether them can run on your side. And the third question answer is Yes. you need StorID in Visual Stuido 2008. You can see details in my project.

    My SkyDrive url is https://skydrive.live.com/?cid=bfdf05e934413519#cid=BFDF05E934413519&id=BFDF05E934413519%21121, and the sample is OutlookWinForm2008Issue, OutlookVissueControlIssue.

    In Outlook Control I write a private method to load Outlook View Control.

            private void OutlookViewInit()
            {
                System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
                this.axViewCtl1 = new AxMicrosoft.Office.Interop.OutlookViewCtl.AxViewCtl();
                ((System.ComponentModel.ISupportInitialize)(this.axViewCtl1)).BeginInit();
                this.axViewCtl1.Enabled = true;
                this.axViewCtl1.Location = new System.Drawing.Point(324, 175);
                this.axViewCtl1.Name = "axViewCtl1";
                this.axViewCtl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axViewCtl1.OcxState")));
                this.axViewCtl1.Size = new System.Drawing.Size(192, 192);
                this.axViewCtl1.TabIndex = 0;
                this.axViewCtl1.Dock = System.Windows.Forms.DockStyle.Fill;
                this.axViewCtl1.ContainingControl = this;
                ((System.ComponentModel.ISupportInitialize)(this.axViewCtl1)).EndInit();
                this.Controls.Add(this.axViewCtl1);
            }

    please add it into you Form's constructor function. And before you do it please confirm Outlook View Control in you Visual Stuido 2008 like this:

    If you can't find it, please select it from there:

    I hope it can help you.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    7 martie 2012 05:11
  • hey Tom,

    i posted question on forum, and i hope that you will help me. the only problem that i have is that my aplication is retriving and older mail items ,from a day when i install outlook on my computer,if i use MAPI.is there any other option to search outlook without MAPI. Thanks for reading

    7 martie 2012 08:58
  • Tom,

    Thanks for the samples.  I downloaded the OutlookVissueControlIssue sample, unzipped it and opened it.  When I tried to Build it, I got a missing directive reference error.  What directive/assembly am I missing?

    7 martie 2012 18:58
  • Hi Retrain,

    Do you confirm Outlook View Control has been selected? And do you find it at the place which I mentioned?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    8 martie 2012 02:15
  • It looks like it is all there to me.  What am I missing?

    8 martie 2012 16:08
  • Tom,

    Could it be a problem with the PIA setup on my pc?  I'm on a windows 7 pc but developing with a x86 Project Build Platform.  I have Office 2003  (until the support team upgrades me to 2010) but also have Visio 2010 installed. When I look at the .Net and Com Reference tabs, I have 2 selections for the Office View Control. When I added the Reference on my project, I added the Com reference and Version 1.1.  I've also checked the GAC and there is an Outlook View Control running. 

    8 martie 2012 19:16
  • Hi Retrain,

    OK, I feel this issue more complex than I thought, I will involve some experts into this issue to see whether they can solve it. There might be some time delay, appreciate your patience.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    9 martie 2012 01:32
  • Thank you, Tom.  

    Just to throw another monkey wrench in the works, I found out that Outlook 2010 isn't working in our setup so the tech staff is installing Outlook 2007 and Office 2010 for everything else.  And it is going to be rolled out in steps so we are going to have a combination of Office 2003, Outlook 2007 and Office 2010 that needs to work with the app.   I think I'm going to have to use late binding somehow to support all the various versions.

    Is there a class, book, webinar, and/or tutorial that you can recommend?

    9 martie 2012 17:55
  • Hi,

    After reviewing this thread, I think the best advice I can offer would be to skip using the Outlook View Control (OVC) altogether. While it does have its advantages functionality-wise, and while it is still technically supported, it is not really a key part of our developer platform moving forward (nor has it been for a while) and therefore there are associated risks with using it nowadays. For example, there were some problems with it in Outlook 2010 for calendaring, and it also now suffers from some issues given Outlook's shutdown changes in recent years.

    2612879 Known issues in Outlook 2007 when you use the Outlook View Control
    http://support.microsoft.com/default.aspx?scid=kb;EN-US;2612879

    2511230 Known issues in Outlook 2010 when you use the Outlook View Control
    http://support.microsoft.com/default.aspx?scid=kb;EN-US;2511230

    Overall, is there a reason why you cannot develop an add-in for Outlook that would add a custom ribbon button to do what you need to do on the selected e-mail message in Outlook? This would really be the most straight-forward way to implement this type of solution that would stay within "best practice" as far as Outlook's developer platform goes. Also, please note that the OVC is only supported within the Outlook process nowadays, so your earlier mention of wanting to potentionally use it for a web app would not be supported. Everything Outlook-wise is designed to run where Outlook is running within a typical user context, and the object model is not safe for scripting, so doing client-side automation from IE will not work by default given IE's security settings.

    Also, if you are using Exchange, the other option would be to skip Outlook altogether and use Exchange-based APIs to get a list of messages and do everything directly via Exchange. Overall, that would likely give you a much more "reusable" codebase if you really need to create something to run in different contexts.


    Bill Jacob - Microsoft Customer Service & Support - Developer Messaging

    12 martie 2012 18:20
  • Thanks for the OVC info, Bill.  I will skip the OVC option now that I know it is no longer recommended. 

    The app will need to support multiple versions of Outlook/Office.  Is Late Binding my only option? 

    Are there any good tutorials that I can use to get started for the recommended method(s)?  I ordered a Programming Applications for Microsoft Office Outlook 2007.  I'm hoping it will be a good reference. 

    Are there any other good reference books that I can buy?  I'm willing to do the work but I need some help getting started.         

    Thanks for your patience and assistance!

    13 martie 2012 17:41
  • Hi, I'm in the same problem. Need to show the inbox (or any folder) with the preview inside a Windows Form but no luck...
    14 martie 2012 02:40
  • Hi,

    The Programming Applications for Office Outlook 2007 book is probably the best resource if you are looking for a good overview to get started on the Outlook development platform. I'd consider that more of a how-to guide, however, whereas the documentation on MSDN is more reference material. There weren't too many changes in Outlook 2010, so looking at the What's New topics on MSDN for Outlook 2010 should bridge the gap.

    Overall, given you're pretty new to the platform, and even C#, I'd really suggest first getting this up and running for Outlook 2010. That will get you a working add-in for your strategic future. Then, based on where you are at, you can better decide whether you want to tackle a single add-in for multiple versions. Unfortunately, this can be a bit painful, and I wouldn't recommend it, but this is a probably a good place to start if you want to try going down that road:

    http://blogs.msdn.com/b/vsto/archive/2008/03/20/developing-an-add-in-for-multiple-versions-of-office.aspx


    Bill Jacob - Microsoft Customer Service & Support - Developer Messaging

    16 martie 2012 18:30
  • Thanks, Bill.

    Now how do I use late binding to display the contents of the inbox within a WinForm?  I have a class that uses late binding to get an instance of Outlook and it will open Outlook and display it outside the WinForm.    But I don't want it to run outside of the application.  I want to see the Inbox within the application so the user can click on an email and then click a button on the Winform that will upload the email and its attachments to the database.  I can write the code to upload the file to the database but I can't get Outlook to display within the application using late binding.

    Do I have to loop thru each mail item and populate a listbox or is there someway I can just simply display the inbox folder within a Winform?  Is that what an Explorer object is supposed to do?

    Thanks

    16 martie 2012 18:45
  • There is now way to take UI-type objects in the Outlook object model and integrate them with a standalone application. The OVC was specifically designed for the scenario you are describing, but as stated earlier, it's no longer supported for use outside the Outlook process. So what I was recommending was to "move" your standalone application into Outlook as an add-in. This way you can add ribbon and expose your custom functionality from within Outlook ifself. If this is not possible for some reason, I think you have these three options:

    1. Try to work with the OVC anyway, even though it's not really supported in that scenario. I would not recommend this approach.

    2. Write your own UI from scratch to render the Outlook "items" in your WinForm. This is typically problematic for performance reasons, but you can extract the core data from Outlook (sender, received time, subject, etc.) and render it in your WinForm in some way to allow the user to select an "item."

    3. I haven't looked in a while, but there used to be some third-party controls that functioned much like the OVC. That may be something you may want to search for and consider.

    I realize this is not really what you would like to hear, but unfortunately this is the state of things with the OVC in Outlook 2010.


    Bill Jacob - Microsoft Customer Service & Support - Developer Messaging

    16 martie 2012 19:01
  • Well, Bill, that is definitely not what I wanted to hear but at least now I know what the options are.  We'll look into 3rd party controls and can hopefully find something there.

    Thanks for your help!

    16 martie 2012 19:45