Laden...

Add-In für Outlook 2007 / VS2008 Explorers Probleme

Erstellt von ZeroQool vor 15 Jahren Letzter Beitrag vor 15 Jahren 2.255 Views
Z
ZeroQool Themenstarter:in
322 Beiträge seit 2006
vor 15 Jahren
Add-In für Outlook 2007 / VS2008 Explorers Probleme

Hallo, habe zB folgendes Sample gefunden.

using System;

using System.Windows.Forms;

using Microsoft.VisualStudio.Tools.Applications.Runtime;

using Outlook = Microsoft.Office.Interop.Outlook;

using Office = Microsoft.Office.Core;

using System.Collections.Generic;

using Microsoft.Office.Interop.Outlook;

using Microsoft.TeamFoundation.Client;

using Microsoft.TeamFoundation.WorkItemTracking.Client;

 

namespace EmailToWorkitem

{

    public partial class ThisApplication

    {

        // the prompt and action name

        const string createNewPrompt = "Create Workitem";

 

        Outlook.Explorer _explorer = null;

 

        private void ThisApplication_Startup(object sender, System.EventArgs e)

        {

            // cache the explorer object

            _explorer = this.Explorers.Application.ActiveExplorer();

 

            // when an email selection changes this event will fire

            _explorer.SelectionChange += new ExplorerEvents_10_SelectionChangeEventHandler(_explorer_SelectionChange);

        }

 

        // event fired when any selection changes.

        void _explorer_SelectionChange()

        {

            foreach (object selectedItem in _explorer.Selection)

            {

                // we only want to deal with selected mail items

                MailItem item = selectedItem as MailItem;

                if (item != null)

                {

                    // see if the action already exists on mail item

                    Action newAction = item.Actions[createNewPrompt];

 

                    // and create it if it does not

                    if(newAction == null)

                    {

                        newAction = item.Actions.Add();

                        newAction.Name = createNewPrompt;

                        newAction.ShowOn = OlActionShowOn.olMenu;

                        newAction.Enabled = true;

                        item.Save();

                    }

 

                    // add the event handler for our action

                    item.CustomAction += new ItemEvents_10_CustomActionEventHandler(item_CustomAction);

                }

            }

        }

 

        void item_CustomAction(object Action, object Response, ref bool Cancel)

        {

            try

            {

                Action mailAction = (Action)Action;

                switch (mailAction.Name)

                {

                    // only process the action we know about

                    case createNewPrompt:

                        try

                        {

                            MailItem mailItem = _explorer.Selection[1] as MailItem;

                            if (mailItem != null)

                            {

                                // TODO: modify the server details to point you your server

                                TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer("http://yourserver:8080");

                                WorkItemStore store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));

 

                                // TODO: modify the project name to your project

                                WorkItemTypeCollection workItemTypes = store.Projects["YOURPROJECT"].WorkItemTypes;

 

                                // Enter the work item as a bug

                                WorkItemType wit = workItemTypes["bug"];

                                WorkItem workItem = new WorkItem(wit);

 

                                workItem.Title = mailItem.Subject;

                                workItem.Description = mailItem.Body;

                                workItem.Save();

 

                                MessageBox.Show(string.Format("Created bug {0}", workItem.Id));

                            }

                            else

                            {

                                MessageBox.Show("Unable to convert selected item to a mail item");

                            }

                        }

                        finally

                        {

                            Cancel = true;

                        }

                        break;

                       

                }

            }

            catch (System.Exception e)

            {

                MessageBox.Show(e.ToString());

            }

        }

 

        private void ThisApplication_Shutdown(object sender, System.EventArgs e)

        {

        }

 

        #region VSTO generated code

 

        /// <summary>

        /// Required method for Designer support - do not modify

        /// the contents of this method with the code editor.

        /// </summary>

        private void InternalStartup()

        {

            this.Startup += new System.EventHandler(ThisApplication_Startup);

            this.Shutdown += new System.EventHandler(ThisApplication_Shutdown);

        }

 

        #endregion

    }

}

Nun bemängelt er immer

_explorer = this.Explorers.Application.ActiveExplorer();

Fehler 2 "OutlookAddIn.ThisAddIn" enthält keine Definition für "Explorers", und es konnte keine Erweiterungsmethode "Explorers" gefunden werden, die ein erstes Argument vom Typ "OutlookAddIn.ThisAddIn" akzeptiert. (Fehlt eine Using-Direktive oder ein Assemblyverweis?) C:\VisualStudio\Projects\OutlookAddIn\OutlookAddIn\ThisAddIn.cs 17 28 OutlookAddIn

Weißt jemand vielleicht weiter? Ich glaube nicht, dass es eine USING oder so fehlt.

THX

N
228 Beiträge seit 2005
vor 15 Jahren

Was mir spontan auffällt (ohne die Materie im speziellen zu kennen), dass deine Classe keine Basis-Klasse angibt. Somit kann Explorers nur unbekannt sein.

Schöne Grüße,
Mario

664 Beiträge seit 2005
vor 15 Jahren

Hi

die Zeile sollte so lauten

this.Application.ActiveExplorer();

Ein Blick in die Doku hätte dir das aber auch verraten 😉