这里有每个文件夹的详细信息。现在我想限制它只列出“收件箱下的文件夹” 实际上现在我想列出收件箱下的文件夹。(我在收件箱下创建了文件夹。我不想显示Outbox,Draft& so..on)
mycode的。
private IEnumerable<MAPIFolder> GetAllFolders(Folders folders)
{
foreach (MAPIFolder f in folders)
{
yield return f;
foreach (var subfolder in GetAllFolders(f.Folders))
{
yield return subfolder;
}
}
}
按钮点击事件
private void button1_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Outlook.Application oApp =
new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook._NameSpace ns =
(Microsoft.Office.Interop.Outlook._NameSpace)oApp.GetNamespace("MAPI");
// in here i get the error "userd of unassign local variable".
// without this line code works fine and return all the Folders &
// Sub folders.
Microsoft.Office.Interop.Outlook.MAPIFolder oPublicFolder =
olNS.GetDefaultFolder(
Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
foreach (var f in GetAllFolders(ns.Folders))
{
//if (f == oPublicFolder) continue;
if (f.DefaultItemType == OlItemType.olMailItem)
{
string ff = f.Name;
//Some codings here
}
}
}
这有时候是一个愚蠢的问题,因为有时它可能很简单。但在这里,我要求你们伸出援助之手。
答案 0 :(得分:0)
// Create Application class and get namespace
Outlook.Application outlook = new Outlook.ApplicationClass();
Outlook.NameSpace ns = outlook.GetNamespace("Mapi");
object _missing = Type.Missing;
ns.Logon(_missing, _missing, false, true);
// Get Inbox information in objec of type MAPIFolder
Outlook.MAPIFolder inbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
// Unread emails
int unread = inbox.UnReadItemCount;
// Display the subject of emails in the Inbox folder
foreach (Outlook.MailItem mail in inbox.Items)
{
Console.WriteLine(Wmail.Subject);
}
在内盒中发现子文件夹名称
Microsoft.Office.Interop.Outlook.Application outlook = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.NameSpace ns = outlook.GetNamespace("Mapi");
object _missing = Type.Missing;
ns.Logon(_missing, _missing, false, true);
// Get Inbox information in objec of type MAPIFolder
Microsoft.Office.Interop.Outlook.MAPIFolder inbox = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
// Unread emails
int unread = inbox.UnReadItemCount;
// Display the subject of emails in the Inbox folder
foreach (Microsoft.Office.Interop.Outlook.Folder folds in inbox.Folders)
{
Console.WriteLine(folds.Name);
}