我正在写一个应用程序,将操作Outlook数据。我想使该数据第一次备份,我希望我可以通过接触/日历项目只是圈等,并把它们写出来到PST文件。
I'm writing an app that will manipulate Outlook data. I want to make a backup of that data first and am hoping I could just loop through the contact/calendar items, etc and write them out to a PST file.
我怎么能写1使用。NET的内容或几个Outlook文件夹到PST? [VB或者C#无论]
How can I write the contents of 1 or several Outlook folders to a PST using .Net? [vb or c# no matter]
我能够从各种互联网和MSDN文档各地的样本拼凑这个code一起。这将允许您选择一个Outlook高水平的文件夹,然后将备份所有文件夹下面。在我来说,我从未想过邮件文件夹,所以我将其排除。
I was able to piece this code together from a variety of samples around the internet and MSDN docs. This will allow you to choose an outlook high level folder and will backup all folders underneath. In my case I didn't actually want mail folders so I exclude them.
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