2011-05-11 86 views
0

我有這個功能谷歌日曆API asp.net C#刪除事件

private static void DeleteEvent(CalendarService service, string pTitle,DateTime pDate) 
    { 
     FeedQuery query = new FeedQuery(); 
     query.Uri = new Uri("http://www.google.com/calendar/feeds/default/private/full"); 
     AtomFeed calFeed = service.Query(query); 
     foreach (AtomEntry entry in calFeed.Entries) 
     { 
      if (pTitle.Equals(entry.Title.Text)) 
      { 
       entry.Delete(); break; 
      } 
     } 
    } 

我如何通過名稱和日期刪除事件?

回答

0

這些可能幫助:

http://code.google.com/apis/calendar/data/2.0/developers_guide_dotnet.html#DeletingEvents
http://code.google.com/apis/calendar/data/2.0/developers_guide_dotnet.html#RetrievingEvents

我猜類似如下可能的工作:

EventQuery query = new EventQuery("https://www.google.com/calendar/feeds/default/private/full"); 
query.StartDate = ...; 
query.EndDate = ...; 
EventFeed feed = service.Query(query); 
foreach (var entry in feed.Entries) 
{ 
    if (pTitle.Equals(entry.Title.Text)) 
    { 
     entry.Delete(); break; 
    } 
} 
0

儘管上述解決方案將工作,但我會建議另一種方法。除了每次遍歷所有事件並刪除之外,爲什麼不要讓Google爲您找到具體的事件。它可以通過使用ExtendedProperty下面

  1. 的辦法分配一個ID(與您在您的數據庫中設置)所添加的每個事件來完成。
  2. 刪除當您將要刪除的ID,並使用查詢獲取爲您
  3. 刪除特定事件

Google.GData.Calendar.EventEntry Entry = new Google.GData.Calendar.EventEntry(); 

//create the ExtendedProperty and add the EventID in the new event object, 
//so it can be deleted/updated later 
ExtendedProperty oExtendedProperty = new ExtendedProperty(); 
oExtendedProperty.Name = "EventID"; 
oExtendedProperty.Value = GoogleAppointmentObj.EventID; 
Entry.ExtensionElements.Add(oExtendedProperty); 

string ThisFeedUri = "http://www.google.com/calendar/feeds/" + CalendarID 
+ "/private/full"; 
Uri postUri = new Uri(ThisFeedUri); 

//create an event query object and attach the EventID to it in Extraparameters 
EventQuery Query = new EventQuery(ThisFeedUri); 
Query.ExtraParameters = "extq=[EventID:" + GoogleAppointmentObj.EventID + "]"; 
Query.Uri = postUri; 

//Find the event with the specific ID 
EventFeed calFeed = CalService.Query(Query); 

//if search contains result then delete 
if (calFeed != null && calFeed.Entries.Count > 0) 
{ 
    foreach (EventEntry SearchedEntry in calFeed.Entries) 
    { 
     SearchedEntry.Delete(); 
     break; 
    } 

}