[英]google calendar api asp.net c# delete event
我有這個功能
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;
}
}
}
如何按標題和日期刪除事件?
盡管上述解決方案有效,但我建議另一種方法。 與其每次都遍歷所有事件並刪除所有事件,不如讓Google為您查找特定事件。 可以通過使用ExtendedProperty
使用以下方法來完成
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;
}
}
這些可能會幫助:
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;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.