Programming example of vsto Outlook project and folder

Source: Internet
Author: User
Tags microsoft outlook
Microsoft Outlook object models are generally used to access various types of projects in folders. This article contains examples of methods, properties, and objects that can be used to reference outlook projects and Outlook folders by using Microsoft Visual C #. net.

This article contains the following topics and related examples:

    • Reference existing folders

      • GetdefaultfolderMethod
      • FoldersObject
      • ParentAttribute
      • GetshareddefaultfolderMethod
      • GetfolderfromidMethod
    • Create new folder and reference new folder
      • Folders. AddMethod
    • Create and reference a new project
      • CreateitemMethod
      • Items. AddMethod
      • CreateitemfromtemplateMethod
    • Reference an existing project
      • Using items (I)Method
      • Using items ("subject ")Method
      • FindMethod
      • RestrictMethod
      • GetitemfromidMethod

 

 

Reference existing folders

Getdefaultfolder Method

The default folder is the folder at the same level as the inbox that receives incoming mail. If the configuration file contains multiple "inbox", you can press Ctrl + Shift + I to select the default "inbox ". Default folders are those that are regularly used, such as the "calendar" folder, "contacts" folder, and "task" folder. You can useGetdefaultfolderTo easily reference these folders.GetdefaultfoldersThe method uses a parameter to define the folder type you want to reference. The outlook object has an enumeration that you can select. This enumeration is defined in the outlook. oldefaultfolders Enumeration type. The following exampleCodeSetOfolderSpecify the object variable to the default "inbox" folder.

 

Outlook. _ application olapp = new outlook. applicationclass (); outlook. _ namespace olns = olapp. getnamespace ("mapi ");

Outlook. mapifolder ofolder = olns. getdefaultfolder (outlook. oldefaultfolders. olfolderinbox); console. Write (ofolder. Name );

 

Folders object

AvailableFoldersTo reference any folder in the outlook folder list.FoldersObjects are usually used to reference the Microsoft Exchange folder or any other folder that is not the default outlook folder.

The following sample code illustrates how to reference a public folder named "my public folder. Note that you usually start from the top folder and then look down for the folder you must reference. Note that the folder name is case sensitive. You must make the folder case and name exactly match the display in the outlook folder list.

 

// Todo: Add code here to start the application.
Outlook. _ application olapp = new outlook. applicationclass ();
Outlook. _ namespace olns = olapp. getnamespace ("mapi"); outlook. _ folders ofolders;
Ofolders = olns. Folders;
Outlook. mapifolder opublicfolder = ofolders. Item ("public folders ");
Ofolders = opublicfolder. Folders;
Outlook. mapifolder oallpfolder = ofolders. Item ("all public folders ");
Ofolders = oallpfolder. Folders;
Outlook. mapifolder omyfolder = ofolders. Item ("My public folder ");
Console. Write (omyfolder. Name );

 

 

Folders object

AvailableFoldersTo reference any folder in the outlook folder list.FoldersObjects are usually used to reference the Microsoft Exchange folder or any other folder that is not the default outlook folder.

The following sample code illustrates how to reference a public folder named "my public folder. Note that you usually start from the top folder and then look down for the folder you must reference. Note that the folder name is case sensitive. You must make the folder case and name exactly match the display in the outlook folder list.

 

// Todo: Add code here to start the application.
Outlook. _ application olapp = new outlook. applicationclass ();
Outlook. _ namespace olns = olapp. getnamespace ("mapi"); outlook. _ folders ofolders;
Ofolders = olns. Folders;
Outlook. mapifolder opublicfolder = ofolders. Item ("public folders ");
Ofolders = opublicfolder. Folders;
Outlook. mapifolder oallpfolder = ofolders. Item ("all public folders ");
Ofolders = oallpfolder. Folders;
Outlook. mapifolder omyfolder = ofolders. Item ("My public folder ");

 

 

Getshareddefaultfolder Method

If another user has granted you the permission to use a default folder, you can use this method. You can useGetdefaultfolderUse the same methodGetshareddefaultfolderMethod, but you must specify another parameter. This additional parameter is used to specify the name of a folder belonging to another person. This folder is the folder you want to reference. The following sample code parses the name of another person to verify whether the name of the person is valid and whether the name can be usedGetshareddefaultfolderMethod.

 

Getshareddefaultfolder:

// Todo: Add code here to start the application.
Outlook. _ application olapp = new outlook. applicationclass ();
Outlook. _ namespace olns = olapp. getnamespace ("mapi ");
Outlook. Recipient orecip = olns. createrecipient ("Brian Baker ");
Orecip. Resolve ();
If (orecip. resolved)
{
Outlook. mapifolder ofolder = olns. getshareddefaultfolder (orecip, outlook. oldefaultfolders. olfoldercalendar );
Console. Write (ofolder. Name );
}

 

 

Reference: http://support.microsoft.com/kb/310244/zh-cn

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.