none
Check Selceted Folder in Outlook 2007 RRS feed

  • Question

  • Hi,

         Kindly help me how to check the selected folder is inbox or not in outlook 2007 using c#?

    Thanq advance,

    Jeyamani & Ashwin

    Our Website : www.hoopla.co.in

    • Moved by Paul Zhou Tuesday, February 14, 2012 7:56 AM move for better support (From:.NET Platform Architecture Development Discussions)
    Friday, February 10, 2012 4:25 AM

Answers

  • You can try below code snipet, or visit http://msdn.microsoft.com/en-us/library/ms268994(v=vs.80).aspx

    Microsoft.Office.Interop.Outlook.Application myOlApp =
                    new Microsoft.Office.Interop.Outlook.Application();
                Microsoft.Office.Interop.Outlook.Explorer exp = myOlApp.ActiveExplorer();
                
                if (exp.Selection.Count > 0)
                {
                    Object selObject = exp.Selection[1];
                    if (selObject is Microsoft.Office.Interop.Outlook.MailItem)
                    {
                        MailItem mailItem = selObject as MailItem;
                        Console.WriteLine("Selected mailItem Body is " + mailItem.Body);
                    }
                }
    Are you on outlook-Addin development side ? For more specific question related to Office Development you can ask question to Visual Studio Tools for Office for prompt response.

    Lingaraj Mishra

    Saturday, February 11, 2012 9:22 AM

All replies

  • Below Code-sniptet should work fine for you.

    Microsoft.Office.Interop.Outlook.Application myOlApp =
                    new Microsoft.Office.Interop.Outlook.Application();
    Microsoft.Office.Interop.Outlook.Explorer exp=myOlApp.ActiveExplorer();
    Console.WriteLine(exp.CurrentFolder.Name);

    Friday, February 10, 2012 6:09 AM
  • Thanq Lingaraj.., Its useful..,

    Jey

    Friday, February 10, 2012 11:30 AM
  • how to check any mail item selected in outlook 2007 using c#?

    Thanq advance,

    Jey


    Jey

    Friday, February 10, 2012 12:58 PM
  • You can try below code snipet, or visit http://msdn.microsoft.com/en-us/library/ms268994(v=vs.80).aspx

    Microsoft.Office.Interop.Outlook.Application myOlApp =
                    new Microsoft.Office.Interop.Outlook.Application();
                Microsoft.Office.Interop.Outlook.Explorer exp = myOlApp.ActiveExplorer();
                
                if (exp.Selection.Count > 0)
                {
                    Object selObject = exp.Selection[1];
                    if (selObject is Microsoft.Office.Interop.Outlook.MailItem)
                    {
                        MailItem mailItem = selObject as MailItem;
                        Console.WriteLine("Selected mailItem Body is " + mailItem.Body);
                    }
                }
    Are you on outlook-Addin development side ? For more specific question related to Office Development you can ask question to Visual Studio Tools for Office for prompt response.

    Lingaraj Mishra

    Saturday, February 11, 2012 9:22 AM
  • Hi.,

         Ya thanq for ur answer.., but it throw exception while active explorer closed in Outlook.., 

    Thanq in advance,


    Jey www.hoopla.co.in

    Tuesday, February 14, 2012 5:28 AM
  • What Exception you get ?

    We have set of experts on Visual Studio Tools for Office. You can move your question to the said forum or can start a new thread after closing this thread.


    Lingaraj Mishra

    Tuesday, February 14, 2012 6:31 AM
  • First of all - what application are you developing? standalone (winforms) or outlook add-in?
    Tuesday, February 14, 2012 8:39 AM
  • Outlook Addin 2007

    Jey www.hoopla.co.in

    Tuesday, February 14, 2012 10:10 AM
  • Ok, describe now what do you want to achieve and gives you trouble.

    • Marked as answer by Jey Dude Tuesday, February 14, 2012 10:33 AM
    • Unmarked as answer by Jey Dude Tuesday, February 14, 2012 10:34 AM
    Tuesday, February 14, 2012 10:14 AM
  • Hi..,

           Ya tell me.., I need to if activeexplorer open or closed...,


    Jey www.hoopla.co.in

    Tuesday, February 14, 2012 10:42 AM
  • grab instance of Application (either the one you get in your main AddIn class, or as a .Appointment property from almost any object in outlook) and check Explorers collection on it - Count property will tell you how many explorers are open and if it would be safe to call ActiveExplorer.

    Tuesday, February 14, 2012 11:31 AM
  • Thanks for ur reply.., aciverexplorer().selection returns null object

    Jey www.hoopla.co.in

    Tuesday, February 14, 2012 11:41 AM
  • You have to be prepared for that - if nothing worth of mention (from outlook perspective) is selected then it can be null. You can always try to use Explorer.CurrentFolder, but also be prepared that this could be null.

    Tuesday, February 14, 2012 11:55 AM
  • sorry i cant understood..,

    Regards


    Jey www.hoopla.co.in

    Friday, February 17, 2012 8:29 AM
  • In your code you must be prepared to handle situation where Selection is null - it means that nothing is selected. It is a normal situation and you must always check this, for example using 'if' statement.
    Friday, February 17, 2012 10:40 AM