Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从outlook日历获取数据?_C#_Outlook_Office Interop - Fatal编程技术网

C# 如何从outlook日历获取数据?

C# 如何从outlook日历获取数据?,c#,outlook,office-interop,C#,Outlook,Office Interop,如何从Microsoft outlook日历获取数据事件 并将其放入SQL数据库中。 我尝试过以下代码: public class SamplesCalendar { public static void Main() { Outlook.Application msOutlook = new Outlook.Application(); Outlook.NameSpace session = msOutlook.Session;

如何从Microsoft outlook日历获取数据事件 并将其放入SQL数据库中。 我尝试过以下代码:

public class SamplesCalendar
{
    public static void Main()
    {
        Outlook.Application msOutlook = new Outlook.Application();
        Outlook.NameSpace session = msOutlook.Session;
        Outlook.Stores stores = session.Stores;
        out
        foreach (Outlook.Store store in stores)
        {
            Outlook.MAPIFolder folder = store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);

            folder.GetCalendarExporter();

            Console.WriteLine(folder.FolderPath);

            folder.GetCalendarExporter();
            folder.Items.GetNext();
            LinkedList c = new LinkedList();
            Items CalendarItems = folder.Items;
            for (int i = 0; i <= folder.Items.Count; i++){
                c.AddFirst(1);
            }
            c.printAllNodes();
            Console.WriteLine("Hello");
        }

        Console.ReadLine();
    }
    public class Node
    {
        public Node next;
        public Object data;
    }

    public class LinkedList
    {
        private Node head;

        public void printAllNodes()
        {
            Node current = head;
            while (current != null)
            {
                Console.WriteLine(current.data);
                current = current.next;
            }
        }

        public void AddFirst(Object data)
        {
            Node toAdd = new Node();

            toAdd.data = data;
            toAdd.next = head;

            head = toAdd;
        }

        public void GetAllCalendarItems()
        {
            Microsoft.Office.Interop.Outlook.Application oApp = null;
            Microsoft.Office.Interop.Outlook.NameSpace mapiNamespace = null;
            Microsoft.Office.Interop.Outlook.MAPIFolder CalendarFolder = null;
            Microsoft.Office.Interop.Outlook.Items outlookCalendarItems = null;

            oApp = new Microsoft.Office.Interop.Outlook.Application();
            mapiNamespace = oApp.GetNamespace("MAPI"); ;
            CalendarFolder = mapiNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
            outlookCalendarItems = CalendarFolder.Items;
            outlookCalendarItems.IncludeRecurrences = true;

            foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in outlookCalendarItems)
            {
                if (item.IsRecurring)
                {
                    Microsoft.Office.Interop.Outlook.RecurrencePattern rp = item.GetRecurrencePattern();
                    DateTime first = new DateTime(2008, 8, 31, item.Start.Hour, item.Start.Minute, 0);
                    DateTime last = new DateTime(2008, 10, 1);
                    Microsoft.Office.Interop.Outlook.AppointmentItem recur = null;

                    for (DateTime cur = first; cur <= last; cur = cur.AddDays(1))
                    {
                        try
                        {
                            recur = rp.GetOccurrence(cur);
                            Console.WriteLine(recur.Subject + " -> " + cur.ToLongDateString());
                        }
                        catch
                        { }
                    }
                }
                else
                {
                    Console.WriteLine(item.Subject + " -> " + item.Start.ToLongDateString());
                }
            }

        }
    }
}
公共类示例日历
{
公共静态void Main()
{
Outlook.Application msOutlook=新建Outlook.Application();
Outlook.NameSpace session=msOutlook.session;
Outlook.Stores=session.Stores;
出来
foreach(Outlook.Store商店中的商店)
{
Outlook.MAPIFolder folder=store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
folder.GetCalendarExporter();
Console.WriteLine(folder.FolderPath);
folder.GetCalendarExporter();
folder.Items.GetNext();
LinkedList c=新建LinkedList();
Items CalendarItems=文件夹.Items;

对于(int i=0;i,使用此代码可以在Outlook日历中获取所有项目:

        var outlookApplication = new Application();
        NameSpace mapiNamespace = outlookApplication.GetNamespace("MAPI");
        MAPIFolder calendar = mapiNamespace.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);

        if (calendar != null)
        {
            for (int i = 1; i <= calendar.Items.Count; i++)
            {
                var calendarItem = (AppointmentItem) calendar.Items[i];
            }
        }
var-outlookApplication=new Application();
NameSpace mapiNamespace=outlookApplication.GetNamespace(“MAPI”);
MAPIFolder calendar=mapiNamespace.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
如果(日历!=null)
{

对于(int i=1;i您可以使用以下代码读取日历数据:

using System;
using System.Reflection;
using Outlook = Microsoft.Office.Interop.Outlook;

namespace RetrieveAppointment
{
   public class Class1
   {
      public static int Main(string[] args)
      {
         try 
         {
            // Create the Outlook application.
            Outlook.Application oApp = new Outlook.Application();

            // Get the NameSpace and Logon information.
            // Outlook.NameSpace oNS = (Outlook.NameSpace)oApp.GetNamespace("mapi");
            Outlook.NameSpace oNS = oApp.GetNamespace("mapi");

            //Log on by using a dialog box to choose the profile.
            oNS.Logon(Missing.Value, Missing.Value, true, true); 

            //Alternate logon method that uses a specific profile.
            // TODO: If you use this logon method, 
            // change the profile name to an appropriate value.
            //oNS.Logon("YourValidProfile", Missing.Value, false, true); 

            // Get the Calendar folder.
            Outlook.MAPIFolder oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);

            // Get the Items (Appointments) collection from the Calendar folder.
            Outlook.Items oItems = oCalendar.Items;

            // Get the first item.
            Outlook.AppointmentItem oAppt = (Outlook.AppointmentItem) oItems.GetFirst();


            // Show some common properties.
            Console.WriteLine("Subject: " + oAppt.Subject);
            Console.WriteLine("Organizer: " + oAppt.Organizer);
            Console.WriteLine("Start: " + oAppt.Start.ToString());
            Console.WriteLine("End: " + oAppt.End.ToString());
            Console.WriteLine("Location: " + oAppt.Location);
            Console.WriteLine("Recurring: " + oAppt.IsRecurring);

            //Show the item to pause.
            oAppt.Display(true);

            // Done. Log off.
            oNS.Logoff();

            // Clean up.
            oAppt = null;
            oItems = null;
            oCalendar = null;
            oNS = null;
            oApp = null;
         }

            //Simple error handling.
         catch (Exception e)
         {
            Console.WriteLine("{0} Exception caught.", e);
         }  

         //Default return value
         return 0;

      }
   }
}
有关更多信息,请参阅此链接:


谢谢Alina,但我如何从outlook的另一个日历(如“meeting room 1”@diya)中获取此数据?您可以使用PickFolder()而不是GetDefaultFolder(),在那里您可以选择您的文件夹。如果您选择它,您可以获取文件夹的id。使用此id,您可以使用GetFolderFromID(“yourId”)获取此文件夹.GetFolderFromID也在代码中的同一位置使用。我发现“Application()”这个词有一个错误,我如何修复它it@diya我安装了nuget软件包Microsoft.Office.Interop.Outlook。然后会找到它。如果没有,请尝试这样定义它:新建Microsoft.Office.Interop.Outlook.Application()