How to: Copy Items in Outlook
Applies to |
---|
The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office. Project type
Microsoft Office version
For more information, see Features Available by Application and Project Type. |
This example creates a copy of a mail item and displays it to the user.
Example
Private Sub ThisAddIn_Startup(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Startup
Dim mail As Outlook.MailItem = _
TryCast(Me.Application.GetNamespace("MAPI"). _
GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox). _
Items.GetFirst(), Outlook.MailItem)
If mail IsNot Nothing Then
' Create a copy of the item.
Dim copyMail As Outlook.MailItem = _
TryCast(mail.Copy(), Outlook.MailItem)
' Show the copy to the user.
copyMail.Display(True)
End If
End Sub
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Outlook.MailItem mail = this.Application.GetNamespace("MAPI").
GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox).
Items.GetFirst() as Outlook.MailItem;
if (mail != null)
{
// Create a copy of the item.
Outlook.MailItem copyMail = mail.Copy() as Outlook.MailItem;
// Show the copy to the user.
copyMail.Display(true);
}
}
See Also
Tasks
How to: Create Custom Folder Items
How to: Retrieve a Folder by Name