Export (0) Print
Expand All

_Views.Add method

Creates a new view in the Views collection.

Namespace:  Microsoft.Office.Interop.Outlook
Assembly:  Microsoft.Office.Interop.Outlook (in Microsoft.Office.Interop.Outlook.dll)

[DispIdAttribute()]
View Add(
	string Name,
	OlViewType ViewType,
	OlViewSaveOption SaveOption
)

Parameters

Name
Type: System.String

The name of the new view.

ViewType
Type: Microsoft.Office.Interop.Outlook.OlViewType

The type of the new view.

SaveOption
Type: Microsoft.Office.Interop.Outlook.OlViewSaveOption
  • The save option that specifies the permissions of the new view. olViewSaveOptionAllFoldersOfType The view can be accessed in all folders of this type.

  • olViewSaveOptionThisFolderEveryOne The view can be accessed by all users in this folder only.

  • olViewSaveOptionThisFolderOnlyMe The view can be accessed in this folder only by the user.

Return value

Type: Microsoft.Office.Interop.Outlook.View
A View object that represents the new view.

If you add a View to a Views collection of a folder that is not the current folder, you must first save a copy of the Views collection object and then add the View to this collection object, as shown in the code sample below. This is a work-around for an existing problem which will otherwise cause a call to View.Apply for the added View to fail.

private void CalendarView()
{
    Outlook.View calView;
    Outlook.Views vws;

    Application.ActiveExplorer().CurrentFolder = 
        Application.Session.GetDefaultFolder( 
        Outlook.OlDefaultFolders.olFolderInbox);

    // Current folder is Inbox; add a View to the Calendar folder which 
    //is not the current folder. Keep a copy of the object for the 
    //Views collection for the Calendar
    vws = Application.Session.GetDefaultFolder( 
        Outlook.OlDefaultFolders.olFolderCalendar).Views;

    //Add the View to this Views collection object
    calView = vws.Add("New Calendar",
        Outlook.OlViewType.olCalendarView, 
        Outlook.OlViewSaveOption.olViewSaveOptionThisFolderEveryone);
    calView.Save();
    // This Apply call will be fine.
    calView.Apply();
}
Show:
© 2015 Microsoft