2013-08-07 46 views
1

我正在開發我的Google日曆集成應用程序。當我將參加者添加到EventAttendee對象時,出現「對象未初始化」的錯誤。請檢查下面的代碼...在Google日曆活動中添加參加者

Event Entry = new Event(); 
    Entry.Summary = MeetingName; 
    Entry.Description = MeetingDetails; 

    EventDateTime dt_Start = new EventDateTime(); 
    dt_Start.DateTime = meeting.StartTime.ToString("yyyy-MM-ddThh:mm:ss.000Z"); 
    Entry.Start = dt_Start; 

    EventDateTime dt_End = new EventDateTime(); 
    dt_End.DateTime = meeting.EndTime.ToString("yyyy-MM-ddThh:mm:ss.000Z"); 
    Entry.End = dt_End;   
    if (invitees != null) 
    { 
     foreach (Participant invitee in invitees) 
     { 
      String str = invitee.Email; 
      str = invitee.Name; 
      Entry.Attendees.Add(new EventAttendee() 
      { 
       Email = invitee.Email, 
       DisplayName = WEB.HttpUtility.HtmlDecode(invitee.Name), 
       ResponseStatus = "accepted", 
       Organizer=false, 
       Resource=false 
      }); 
     } 
    } 

的地方,我在做什麼「Entry.Attendees.Add(新EventAttendee()」在這一點上我得到的錯誤...

回答

0

你不應該除了與會者的電子郵件地址之外,還要設置其他參與者的回覆狀態(爲什麼您能接受我創建的會議?),組織者和資源屬性由Google設置。可能可以設置DisplayName但它不是強制性的。

+0

感謝您的答覆......甚至只指定電子郵件地址和顯示名稱後後,我得到了未初始化對象的相同問題。 eventatteendee的其他屬性是AdditionalGuest,Comment,Id,Optional,Self。那麼你能告訴我什麼是我需要指定的其他事情。 –

+0

問題已解決..我在創建eventatteendeee的單獨對象後執行了相同的過程,結果工作正常。 –

1

我認爲你需要首先實例化EventAttendees的列表。

嘗試添加此創建入門

Entry.Attendees = new List<EventAttendee>(); 

然後,你可以試試這個添加他們 -

var att = new EventAttendee() 
        { 
         DisplayName = "Bill Smith", 
         Email = "[email protected]", 
         Organizer = false, 
         Resource = false, 
        }; 
Entry.Attendees.Add(att);