Dot-Net
如何使用 .Net 創建 Outlook PST 文件?
我正在編寫一個將操縱 Outlook 數據的應用程序。我想先備份該數據,並希望我可以遍歷聯繫人/日曆項目等並將它們寫入 PST 文件。
如何使用 .Net 將 1 個或多個 Outlook 文件夾的內容寫入 PST?
$$ vb or c# no matter $$
我能夠從 Internet 和 MSDN 文件中的各種範例中拼湊出這段程式碼。這將允許您選擇 Outlook 高級文件夾並備份下面的所有文件夾。就我而言,我實際上並不想要郵件文件夾,所以我將它們排除在外。
Const BACKUP_PST_PATH As String = "C:\backup.pst" Dim oFolder As Outlook.MAPIFolder = Nothing Dim oMailbox As Outlook.MAPIFolder = Nothing Dim app As New Outlook.Application() Dim ns As Outlook.NameSpace = app.GetNamespace("MAPI") Try //if the file doesn not exist, outlook will create it ns.AddStore(BACKUP_PST_PATH) oFolder = ns.Session.Folders.GetLast() oMailbox = ns.PickFolder() For Each f As Outlook.Folder In oMailbox.Folders If f.DefaultItemType <> Microsoft.Office.Interop.Outlook.OlItemType.olMailItem And f.FolderPath <> oFolder.FolderPath Then f.CopyTo(oFolder ) End If Next ns.RemoveStore(oFolder) Catch ex As Exception ns.RemoveStore(oFolder) IO.File.Delete(BACKUP_PST_PATH) Throw ex End Try