1

我試圖弄清楚如何限制Outlook 2010中的一個文件夾從刪除郵件項目。我有下面的代碼示例運行良好,但只適用於收件箱文件夾(OlDefaultFolders.olFolderInbox)。我試圖找出如何限制收件箱下方的一個文件夾和一個文件夾。例如,我想阻止用戶從ReadMail中刪除的Inbox \ ReadMail。提前感謝您的幫助。防止在Outlook收件箱的一個特定子文件夾中刪除電子郵件

public partial class ThisAddIn 
{ 
    Microsoft.Office.Interop.Outlook.MailItem mail = null; 
    Outlook.Inspectors inspectors = null; 
    Outlook.Folder fldr = null; 

    private void ThisAddIn_Startup(object sender, System.EventArgs e) 
    { 
     inspectors = this.Application.Inspectors; 

     // Is there a way to edit the folloing line to point to a certain sub folder of the inbox folder? 
     inspectors.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler (Inspectors_NewInspector); 

     fldr = (Outlook.Folder)this.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox); 

     fldr.BeforeItemMove += new Microsoft.Office.Interop.Outlook.MAPIFolderEvents_12_BeforeItemMoveEventHandler(fldr_BeforeItemMove); 

    } 

    void fldr_BeforeItemMove(object Item, Microsoft.Office.Interop.Outlook.MAPIFolder MoveTo, ref bool Cancel) 
    { 
     MessageBox.Show("You are not permitted to delete emails from this folder"); 
     Cancel = true; 
    } 

回答

2

替換行

fldr = (Outlook.Folder)this.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox); 

fldr = (Outlook.Folder)this.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox).Folders["ReadMail"]; 
+0

由於梅德! –

+0

我錯過了.Folders ...我也問了錯誤的問題。我需要防止從存儲級別刪除刪除,而不是在收件箱文件夾級別下,所以我結束了這個 - fldr =(Outlook.Folder)this.Application.Session.DefaultStore.GetRootFolder()。Folders [「ReadMail」] ;但是你讓我沿着正確的道路發展,可以這麼說:) –

+0

如果你在Outlook 2003或更舊的版本上運行,商店不公開,但是你仍然可以通過打開收件箱文件夾的父代來使你的代碼工作:Application.Session .GetDefaultFolder(olFolderInbox).Parent.Folders [ 「readmail將」]; –

相關問題