요약
이 문서에서는 Microsoft Outlook 10.0 개체 라이브러리를 사용하여 찾기 메서드 및 제한 메서드를 사용하여 특정 메시지를 검색하는 방법을 C#.
추가 정보
Microsoft Outlook 10.0 개체 라이브러리를 사용하여 특정 메시지를 검색하는 경우 다음 단계를 수행합니다.
-
.NET Microsoft Visual Studio 또는 2005 Microsoft Visual Studio 시작합니다.
-
파일 메뉴에서 새로 고를 클릭한 다음, Project.
-
Visual C# 프로젝트 유형 목록에서 콘솔 애플리케이션을 클릭합니다.
기본적으로 Class1.cs 파일이 만들어집니다.
참고 Microsoft Visual C# 2005에서 Visual C# 프로젝트 유형 목록에서 시각적 C#"를 클릭합니다 . 기본적으로 Program.cs가 만들어집니다. -
Microsoft Outlook 10.0 개체 라이브러리에 대한 참조를 추가합니다. 이렇게 하여 다음 단계를 수행합니다.
-
Project 메뉴에서 참조 추가를 클릭합니다.
-
COM 탭을 클릭하고 Microsoft Outlook 10.0 개체 라이브러리를 찾은 다음 선택을 클릭합니다.
참고 Microsoft Visual C# 2005. 선택을 클릭할 수 있습니다. -
참조 추가 대화 상자에서 확인을 클릭합니다.
-
선택한 라이브러리에 대한 래퍼를 생성하라는 메시지가 표시되면 예를 클릭합니다.
-
-
코드 창에서 코드를 다음으로 바 대체합니다.
using System;
using System.Reflection; // to use Missing.Value
namespace FilterAppointments
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
public static int Main(string[] args)
{
try
{
// Create an Outlook application.
Outlook.Application oApp = new Outlook.Application();
// Get the Mapi NameSpace and the Logon.
Outlook.NameSpace oNS = (Outlook.NameSpace)oApp.GetNamespace("mapi");
// Log on using dialog to choose a profile.
oNS.Logon(Missing.Value, Missing.Value, true, true);
// Alternate Logon using specific profile
// TODO: Change the profile name where it is appropriate.
//oNS.Logon("YourValidProfile", Missing.Value, false, true);
// Get the Calendar folder.
Outlook.MAPIFolder oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
// Get the Items collection in the folder.
Outlook.Items oItems = (Outlook.Items)oCalendar.Items;
Console.WriteLine("Total Items (unrestricted): " + oItems.Count);
//Include all occurrences of recurring items, and then sort them.
oItems.Sort ("[Start]", false);
oItems.IncludeRecurrences = true;
// Define the string for the search criteria.
String sCriteria;
// Set the criteria for the Date fields.
sCriteria = "[Start] <= '09/01/2002 08:00 AM' and [End] >= '2/15/2002 08:00 PM'";
// Set the criteria for a string field.
// sCriteria = "[Subject] = 'Weekly recurring meeting'";
// Set the criteria for a numeric field.
// Look for meetings that have not been responded to.
// sCriteria = "[ResponseStatus] = " + (Int32)Outlook.OlResponseStatus.olResponseNotResponded)
// Use the Restrict method to reduce the number of items to process.
Outlook.Items oRestrictedItems = oItems.Restrict(sCriteria);
oRestrictedItems.Sort ("[Start]", false);
oRestrictedItems.IncludeRecurrences = true;
Console.WriteLine("Total Items Unrestricted : " + oRestrictedItems.Count);
Outlook.AppointmentItem oAppointment;
//Get each item until item is null.
Outlook.AppointmentItem oAppt;
oAppt = (Outlook.AppointmentItem)oRestrictedItems.GetFirst();
while (oAppt != null)
{
// Console.WriteLine(i.ToString());
Console.WriteLine(" Subject: " + oAppt.Subject.ToString());
Console.WriteLine(" Start time: " + oAppt.Start.ToString());
Console.WriteLine(" End time: " + oAppt.End.ToString());
Console.WriteLine(" Occurrences: " + oAppt.RecurrenceState.ToString());
Console.WriteLine("\n\n");
oAppt = (Outlook.AppointmentItem)oRestrictedItems.GetNext();
}
// Use the Find method to get single match.
sCriteria = "[Start] >= '09/30/2001'";
Console.WriteLine("Criteria: " + sCriteria.ToString());
oAppointment = (Outlook.AppointmentItem)oItems.Find(sCriteria);
Console.WriteLine("Used Find with Date fields");
if (oAppointment is Outlook.AppointmentItem)
Console.WriteLine("Found -> " + oAppointment.Subject.ToString());
else
Console.WriteLine("No object found");
// Log off
oNS.Logoff();
// Clean up
oAppointment = null;
oRestrictedItems = 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;
}
}
} -
코드에서 TODO 텍스트 문자열을 검색한 다음 환경에 대한 코드를 수정합니다.
-
F5 키를 눌러 프로그램을 빌드하고 실행합니다.
참조
2002 Outlook 보안 기능에 대한 자세한 내용은 다음 문서 번호를 클릭하여 Microsoft 기술 자료에서 문서를 볼 수 있습니다.
290500 2002
년 Outlook의 개발자 관련 전자 메일 보안 기능에 대한 설명 대규모 컬렉션의 Count 속성을 사용할 때 발생할 수 있는 문제에 대한 추가 정보를 보려면 다음 문서 번호를 클릭하여 Microsoft 기술 자료에서 문서를 볼 수 있습니다.
294385 OL2002: 재발하는 약속을 사용하는 잘못된 Count 속성