c# - How to specify which folder new Outlook AppointmentItems are created in? -


I am creating an object for the object with the following code:

< Pre> Appointment ITEM APT = (AppointmentItem). Cutate item (olimatipip .olapanement item); // Set parameters for 'APT', such as body, subject etc. // ... apt.Save ();

I have a calendar name that I want to put this incident inside, but I did not know which folder should the newly created event go in. New events are always visible in the main calendar folder.

found the solution to provide it on the Kundo Eugene Astaifive

then the above code Should be:

  using Microsoft.Office.Interop.Outlook; Application Approach App = New Application (); MAPIFolder customer_folder = GetMyFolder (Route, Approach App.Sessions Folders); // AppointmentItem apt = (AppointmentItem) customer_folder.Items.Add (OlItemType.olAppointmentItem) to get your folder; // Set parameters for 'APT', such as body, subject etc. // ... apt.Save ();  

and the code for GetMyFolder to find your custom folder consistently:

  using System.Collections; Using System.Linq; Using Microsoft.Office.Interop.Outlook; Private MAPIFolder _mapiFolder; Private MAPIFolder GetMyFolder (string path, IEnumerable folders) {if path! StartsWith (@ "\\", StringComparison.Ordinal)) Empty Return; String pathRoot = GetFolderPathRoot (path); (Folder = & gt; _mapiFolder == faucet). Select the folder (folder = & gt; new {folder, folder Root = GetFolderPathRoot (folder.FolderPath)}). (Where folder (folders & gt; = & gt; folder.footer root == path path). Choose (folder = & gt; folder.folder)) {if (folder.DefaultItemType == OlItemType.olAppointmentItem & folder. FolderPath == path) {s_mapiFolder = folder; break; } If (folder.flowers.cost & lt; folder & gt; (). Any ()) GetMapiFolder (wrong, folders, folders, path); } Return _mapiFolder; } Private Static String GetFolderPathRoot (string folderpath) {// strip header directory separator characters folderPath = folderPath.Remove (0, 2); // A directory separator character intrate index = folder number Find indicator of indexoff (path.directorySepartor cell, 0); // index return string.format (@ "\\ {0}", index> gt; folderpathsbestring (0, index): reconstruct the root path according to the folder path;}  

Edit: Modified code to search consistently in folders under specified path routes.


Comments