0

这里是每个文件夹的详细信息。现在我想限制它只列出“收件箱下的文件夹”实际上现在我想列出收件箱下的文件夹。(我在收件箱下创建了文件夹。我不想显示发件箱、草稿等。 。上 )

我的代码。

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

        }
    }

}

这有时是一个愚蠢的问题,因为有时它可能非常简单。但我在这里向你求助。

4

1 回答 1

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);
            }
于 2013-02-14T06:20:15.447 回答