Outlook 名称';应用程序';在当前上下文中不存在
您好,我正在开发一个解决方案,使用VSTO 2012和microsoft Outlook 2010插件在Outlook 2010中创建工具栏。简而言之,我可以创建Outlook功能区和一个按钮,但无法使用该按钮打开.oft文件。在VisualStudio中,我遇到以下错误“当前上下文中不存在名称“application”。我还添加了对Microsoft Office 14.0对象库的引用。下面是代码Outlook 名称';应用程序';在当前上下文中不存在,outlook,vsto,ribbon,Outlook,Vsto,Ribbon,您好,我正在开发一个解决方案,使用VSTO 2012和microsoft Outlook 2010插件在Outlook 2010中创建工具栏。简而言之,我可以创建Outlook功能区和一个按钮,但无法使用该按钮打开.oft文件。在VisualStudio中,我遇到以下错误“当前上下文中不存在名称“application”。我还添加了对Microsoft Office 14.0对象库的引用。下面是代码 using System; using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Ribbon;
namespace OutlookAddIn8
{
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void CreateItemFromTemplate()
{
Outlook.Folder folder =
Application.Session.GetDefaultFolder(
Outlook.OlDefaultFolders.olFolderDrafts) as Outlook.Folder;
Outlook.MailItem mail =
Application.CreateItemFromTemplate(
@"c:\ivy.oft", folder) as Outlook.MailItem;
mail.Subject = "Congratulations";
mail.Save();
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
}
}
}
感谢您的帮助,我们很感谢您的帮助。这可能是我们错过的简单内容。可以使用
Globals.ThisAddIn.Application
访问应用程序实例。如果将加载项类重命名为其他名称,例如MyAddIn,则命令将为:Globals.MyAddIn.Application
这里有一个包含更多详细信息的链接:最后终于到达了那里,下面是代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace OutlookAddIn3
{
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
Outlook.Application Application = Globals.ThisAddIn.Application;
Outlook.MailItem mail =
Application.CreateItemFromTemplate(
@"Z:\Transfer\Outlook 2010 Templates\testsubject.oft") as Outlook.MailItem;
mail.Display(true);
}
好的,我在哪里输入这个字符串。对不起,我不是一个编码员,我只是想从网上找到的信息中完成这项工作。提前谢谢!只需在函数开头添加:
Outlook.Application=Globals.ThisAddIn.Application代码>非常感谢您消除了错误消息。现在的问题是,我需要代码来在点击按钮时初始化oft。private void button1\u Click(对象发送者,RibbonControlEventArgs e){我有这部分代码,但我应该把它放在哪里?