25

Exchange2007パブリックフォルダに当社の公開カレンダーを設定しています。以下のコードを使用して、当日の個人的なカレンダーの予定を取得できます。オンラインで高低を検索しましたが、パブリックフォルダのカレンダーからカレンダー情報を取得している人の例が見つかりません。

それは実行可能であるはずのようですが、私は一生それを機能させることができません。カレンダーにアクセスするために以下のコードを変更するにはどうすればよいですか?単純なリストを取得するだけで、asp.netを介して予定を作成することに興味はありません。他の提案も受け付けています。ありがとう。

追加の報奨金
-これを行う必要があったのは私だけではありません。将来の世代のためにこの問題を解決してみましょう。


無知のためにもう一度更新-私が取り組んでいるプロジェクトが.NET2.0であるとは言いませんでした(非常に重要だと思いませんか?)

*以下にコードソリューションを追加しました*
-元のコード例を、最終的に機能するコードに置き換えました。最も難しい部分であるパブリックフォルダを見つけるためのコードを提供してくれたOlegに感謝します。ここの例を使用してコードを変更しましたhttp://msexchangeteam.com/archive/2009/04/21/451126.aspxより単純なFindAppointmentsメソッドを使用します。

この簡単な例では、予定を含むhtml文字列が返されますが、必要に応じてカスタマイズするためのベースとして使用できます。以下の彼の答えの下で私たちの前後を見ることができます。

using System;
using Microsoft.Exchange.WebServices.Data;
using System.Net;

namespace ExchangePublicFolders
{
    public class Program
    {
        public static FolderId FindPublicFolder(ExchangeService myService, FolderId baseFolderId,
        string folderName)
        {

        FolderView folderView = new FolderView(10, 0);
        folderView.OffsetBasePoint = OffsetBasePoint.Beginning;
        folderView.PropertySet = new PropertySet(FolderSchema.DisplayName, FolderSchema.Id);

        FindFoldersResults folderResults;
        do
        {
            folderResults = myService.FindFolders(baseFolderId, folderView);

            foreach (Folder folder in folderResults)
                if (String.Compare(folder.DisplayName, folderName, StringComparison.OrdinalIgnoreCase) == 0)
                    return folder.Id;

            if (folderResults.NextPageOffset.HasValue)
                folderView.Offset = folderResults.NextPageOffset.Value;
        }
        while (folderResults.MoreAvailable);

        return null;
    }

    public static string MyTest()
    {
        ExchangeService myService = new ExchangeService(ExchangeVersion.Exchange2007_SP1);

        myService.Credentials = new NetworkCredential("USERNAME", "PASSWORD", "DOMAIN");
        myService.Url = new Uri("https://MAILSERVER/ews/exchange.asmx");

        Folder myPublicFoldersRoot = Folder.Bind(myService, WellKnownFolderName.PublicFoldersRoot);
        string myPublicFolderPath = @"PUBLIC_FOLDER_CALENDAR_NAME";
        string[] folderPath = myPublicFolderPath.Split('\\');
        FolderId fId = myPublicFoldersRoot.Id;
        foreach (string subFolderName in folderPath)
        {
            fId = Program.FindPublicFolder(myService, fId, subFolderName);
            if (fId == null)
            {
                return string.Format("ERROR: Can't find public folder {0}", myPublicFolderPath);

            }
        }

        Folder folderFound = Folder.Bind(myService, fId);
        if (String.Compare(folderFound.FolderClass, "IPF.Appointment", StringComparison.Ordinal) != 0)
        {
            return string.Format("ERROR: Public folder {0} is not a Calendar", myPublicFolderPath);

        }

        CalendarFolder AK_Calendar = CalendarFolder.Bind(myService, fId, BasePropertySet.FirstClassProperties);

        FindItemsResults<Appointment> AK_appointments = AK_Calendar.FindAppointments(new CalendarView(DateTime.Now,DateTime.Now.AddDays(1)));


        string rString = string.Empty;


        foreach (Appointment AK_appoint in AK_appointments)
        {

            rString += string.Format("Subject: {0}<br />Date: {1}<br /><br />",  AK_appoint.Subject, AK_appoint.Start);    
        }

        return rString;
    }

    }
}
4

2 に答える 2

15

ここで約束されているように、コード例があります。Microsoft Exchange Webサービス(EWS)マネージAPI 1.0を使用しましたが、同じようにすることをお勧めします。私がコードに含めたほとんどのコメント

using System;
using Microsoft.Exchange.WebServices.Data;
using System.Net;

namespace ExchangePublicFolders {
    class Program {
        static FolderId FindPublicFolder (ExchangeService myService, FolderId baseFolderId,
            string folderName) {

            // We will search using paging. We will use page size 10
            FolderView folderView = new FolderView (10,0);
            folderView.OffsetBasePoint = OffsetBasePoint.Beginning;
            // we will need only DisplayName and Id of every folder
            // se we'll reduce the property set to the properties
            folderView.PropertySet = new PropertySet (FolderSchema.DisplayName,
                FolderSchema.Id);

            FindFoldersResults folderResults;
            do {
                folderResults = myService.FindFolders (baseFolderId, folderView);

                foreach (Folder folder in folderResults)
                    if (String.Compare (folder.DisplayName, folderName, StringComparison.OrdinalIgnoreCase) == 0)
                        return folder.Id;

                if (folderResults.NextPageOffset.HasValue)
                    // go to the next page
                    folderView.Offset = folderResults.NextPageOffset.Value;
            }
            while (folderResults.MoreAvailable);

            return null;
        }

        static void MyTest () {
            // IMPORTANT: ExchangeService is NOT thread safe, so one should create an instance of
            // ExchangeService whenever one needs it.
            ExchangeService myService = new ExchangeService (ExchangeVersion.Exchange2007_SP1);

            myService.Credentials = new NetworkCredential ("MyUser@corp.local", "myPassword00");
            myService.Url = new Uri ("http://mailwebsvc-t.services.local/ews/exchange.asmx");
            // next line is very practical during development phase or for debugging
            myService.TraceEnabled = true;

            Folder myPublicFoldersRoot = Folder.Bind (myService, WellKnownFolderName.PublicFoldersRoot);
            string myPublicFolderPath = @"OK soft GmbH (DE)\Gruppenpostfächer\_Template - Gruppenpostfach\_Template - Kalender";
            string[] folderPath = myPublicFolderPath.Split('\\');
            FolderId fId = myPublicFoldersRoot.Id;
            foreach (string subFolderName in folderPath) {
                fId = FindPublicFolder (myService, fId, subFolderName);
                if (fId == null) {
                    Console.WriteLine ("ERROR: Can't find public folder {0}", myPublicFolderPath);
                    return;
                }
            }

            // verify that we found 
            Folder folderFound = Folder.Bind (myService, fId);
            if (String.Compare (folderFound.FolderClass, "IPF.Appointment", StringComparison.Ordinal) != 0) {
                Console.WriteLine ("ERROR: Public folder {0} is not a Calendar", myPublicFolderPath);
                return;
            }

            CalendarFolder myPublicFolder = CalendarFolder.Bind (myService,
                //WellKnownFolderName.Calendar,
                fId,
                PropertySet.FirstClassProperties);

            if (myPublicFolder.TotalCount == 0) {
                Console.WriteLine ("Warning: Public folder {0} has no appointment. We try to create one.", myPublicFolderPath);

                Appointment app = new Appointment (myService);
                app.Subject = "Writing a code example";
                app.Start = new DateTime (2010, 9, 9);
                app.End = new DateTime (2010, 9, 10);
                app.RequiredAttendees.Add ("oleg.kiriljuk@ok-soft-gmbh.com");
                app.Culture = "de-DE";
                app.Save (myPublicFolder.Id, SendInvitationsMode.SendToNone);
            }

            // We will search using paging. We will use page size 10
            ItemView viewCalendar = new ItemView (10);
            // we can include all properties which we need in the view
            // If we comment the next line then ALL properties will be
            // read from the server. We can see there in the debug output
            viewCalendar.PropertySet = new PropertySet (ItemSchema.Subject);
            viewCalendar.Offset = 0;
            viewCalendar.OffsetBasePoint = OffsetBasePoint.Beginning;
            viewCalendar.OrderBy.Add (ContactSchema.DateTimeCreated, SortDirection.Descending);

            FindItemsResults<Item> findResultsCalendar;
            do {
                findResultsCalendar = myPublicFolder.FindItems (viewCalendar);

                foreach (Item item in findResultsCalendar) {
                    if (item is Appointment) {
                        Appointment appoint = item as Appointment;
                        Console.WriteLine ("Subject: \"{0}\"", appoint.Subject);
                    }
                }

                if (findResultsCalendar.NextPageOffset.HasValue)
                    // go to the next page
                    viewCalendar.Offset = findResultsCalendar.NextPageOffset.Value;
            }
            while (findResultsCalendar.MoreAvailable);
        }
        static void Main (string[] args) {
            MyTest();
        }
    }
}

myPublicFolderPathパブリックカレンダーフォルダを使用して、文字列を値に更新する必要があります。myService.TraceEnabled = trueデバッグ情報付きの長い出力を生成するものを設定しました。生産のためにラインを削除する必要があります。

更新: ExchangeOWAでの新しいカレンダーシステムサポートの作成にある追加のリンク。ビデオをまだ見たことがなく、Exchange Webサービスを使用したい場合は、そこで見ることをお勧めします。それは将来あなたの時間を節約することができます。

于 2010-09-09T17:13:09.943 に答える
1

Exchange 2003でも同様のことを行いましたが、WebDAV検索方法(http://msdn.microsoft.com/en-us/library/aa143053%28v=EXCHG.65%29.aspx)を使用しました。

http://geekswithblogs.net/cskardon/archive/2008/12/01/hunting-those-elusive-public-folders-using-exchange-web-services-part.aspxが役立つ場合があります。

于 2010-09-07T22:25:56.937 に答える