2017-12-07 22 views
1

리본 버튼 클릭으로 Outlook 약속 항목을 열어야합니다.리본 버튼에서 약속 항목을 여는 방법

var item = control.Context as Inspector; 
AppointmentItem appointmentItem = item.CurrentItem as AppointmentItem; 
    if (appointmentItem != null) 
     { 
      if (appointmentItem.EntryID == null) 
      { 
       appointmentItem.Subject = "New Appointment"; 
       appointmentItem.Body = "Welcome to new appointment"; 
      } 
     } 

이 약속 창을 열어야하지만이 코드 라인에 null 참조 오류주고있다 "VAR 항목을 = 경위 등 control.Context;" 항목이 null입니다.

답변

0

다음은 XML 코드의 예입니다.

<?xml version="1.0" encoding="UTF-8"?> 
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load"> 
    <ribbon> 
    <tabs> 
     <tab idMso="TabAddIns"> 
     <group id="MyGroup" 
       label="My Group"> 
          <button 
            id="btnNewAppointment" 
            label="New Appointment" 
            onAction="NewAppointment" 
            imageMso="NewAppointment" 
            size="large" 
            screentip="New Appointment" 
            supertip="Create a new appointment" 
            /> 
     </group> 
     </tab> 
    </tabs> 
    </ribbon> 
</customUI> 

다음은 C# 코드 예입니다.

public void NewAppointment(Office.IRibbonControl control) 
{ 
    try 
    { 
     Microsoft.Office.Interop.Outlook.Application app = Globals.ThisAddIn.Application; 
     Microsoft.Office.Interop.Outlook.AppointmentItem newAppointment = (Microsoft.Office.Interop.Outlook.AppointmentItem) 
     app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem); 
     newAppointment.Start = DateTime.Now.AddHours(2); 
     newAppointment.End = DateTime.Now.AddHours(3); 
     newAppointment.Location = "ConferenceRoom #2345"; 
     newAppointment.Body = "We will discuss progress on the group project."; 
     newAppointment.AllDayEvent = false; 
     newAppointment.Subject = "Group Project"; 
     newAppointment.Recipients.Add("Roger Harui"); 
     Microsoft.Office.Interop.Outlook.Recipients sentTo = newAppointment.Recipients; 
     Microsoft.Office.Interop.Outlook.Recipient sentInvite = null; 
     sentInvite = sentTo.Add("Holly Holt"); 
     sentInvite.Type = (int)Microsoft.Office.Interop.Outlook.OlMeetingRecipientType.olRequired; 
     sentInvite = sentTo.Add("David Junca "); 
     sentInvite.Type = (int)Microsoft.Office.Interop.Outlook.OlMeetingRecipientType.olOptional; 
     sentTo.ResolveAll(); 
     newAppointment.Save(); 
     newAppointment.Display(true); 
    } 
    catch (Exception ex) 
    { 
     //MessageBox.Show("The following error occurred: " + ex.Message); 
    } 
} 

다음은이 답변이 질문을 해결 되었습니까 마이크로 소프트 How to: Programmatically Create Appointments

+0

의 기사입니까? – aduguid