gpt4 book ai didi

C# Outlook 2010 - 使用 'this.Application' 时出错

转载 作者:太空宇宙 更新时间:2023-11-03 10:57:41 25 4
gpt4 key购买 nike

谁能告诉我为什么会出现以下错误?谷歌没有提供太多帮助。抱歉,这有点含糊。该代码的目的是将所有未读邮件从 Outlook 中取出并放入 C# 窗体中。

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

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

private void button1_Click(object sender, EventArgs e)
{
Outlook.MAPIFolder inbox =
this.Application.ActiveExplorer().Session.GetDefaultFolder
(Outlook.OlDefaultFolders.olFolderInbox);
Outlook.Items unreadItems = inbox.Items.Restrict("[Unread]=true");

MessageBox.Show(
string.Format("Unread items in Inbox = {0}", unreadItems.Count));
}
}
}

错误:“TestEmailGetter.Form1”不包含“Application”的定义,并且找不到接受“TestEmailGetter.Form1”类型的第一个参数的扩展方法“Application”(您是否缺少 using 指令或程序集引用资料?

错误发生在这一行:

this.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

我不知道要添加什么来修复它。 :-(

感谢您的帮助!

最佳答案

你的 Form1类没有成员Application .您必须在没有 this 的情况下使用它如果你想引用 Application 的静态成员来自命名空间的类 Microsoft.Office.Interop.Outlook .

更新

使用 Outlook.Application ...

关于C# Outlook 2010 - 使用 'this.Application' 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18837895/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com