none
Creating public shortcut button in outlook! RRS feed

  • Question

  • Hey all

     

    i have created some buttons for my outlook program which works fine but when i try to open a specifik folder via the buttons it opens in a new outlook window and not in the already open outlook, my code look like this.

    iam not really sure what iam doing wrong can anyone help??? i cant find any help via google all is about VB not C#

     private void henvendelsesMappe(Office.CommandBarButton ctrl, ref bool cancel)
        {
          try
          {
            Outlook.Folder inbox = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox) as Outlook.Folder;
            inbox.Display();
    
          }
          catch (System.Exception ex)
          {
            System.Windows.Forms.MessageBox.Show("Error " + ex.Message.ToString());
          }
        }
    
     

    • Moved by CoolDadTx Monday, May 9, 2011 1:45 PM Office related (From:Visual C# General)
    Monday, May 9, 2011 12:34 PM

Answers

  • Hi allanmoller,

    The code you need is as follows:

    public void SetCurrentFolder()
    {
        string folderName = "TestFolder";
        Outlook.MAPIFolder inBox = (Outlook.MAPIFolder)
            this.Application.ActiveExplorer().Session.GetDefaultFolder
            (Outlook.OlDefaultFolders.olFolderInbox);
        try
        {
            this.Application.ActiveExplorer().CurrentFolder = inBox;
            this.Application.ActiveExplorer().CurrentFolder.Display();
        }
        catch
        {
            System.Windows.Forms.MessageBox.Show("There is no folder named " + folderName +
                ".", "Find Folder Name");
        }
    }

    The following topic has a similar example - How to: Retrieve a Folder by Name.

     

    Cheers!

    Norm E.


    Norm Estabrook
    Monday, May 9, 2011 7:27 PM
    Answerer

All replies

  • Hi allan,

    instead of inbox.Display();

    say

    Application.ActiveExplorer.CurrentFolder = inbox;

    That should do the trick.

    Greets - Helmut


    Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]
    Monday, May 9, 2011 7:14 PM
    Answerer
  • Hi allanmoller,

    The code you need is as follows:

    public void SetCurrentFolder()
    {
        string folderName = "TestFolder";
        Outlook.MAPIFolder inBox = (Outlook.MAPIFolder)
            this.Application.ActiveExplorer().Session.GetDefaultFolder
            (Outlook.OlDefaultFolders.olFolderInbox);
        try
        {
            this.Application.ActiveExplorer().CurrentFolder = inBox;
            this.Application.ActiveExplorer().CurrentFolder.Display();
        }
        catch
        {
            System.Windows.Forms.MessageBox.Show("There is no folder named " + folderName +
                ".", "Find Folder Name");
        }
    }

    The following topic has a similar example - How to: Retrieve a Folder by Name.

     

    Cheers!

    Norm E.


    Norm Estabrook
    Monday, May 9, 2011 7:27 PM
    Answerer
  • Perfect it worked like a charm Thx for help :-)
    Monday, May 9, 2011 8:19 PM