我有这个功能
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 :(得分: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;
}
}
答案 1 :(得分:0)
虽然上述解决方案可行,但我建议采用另一种方法。不是每次都遍历所有事件而是删除(如果找到),为什么不让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;
}
}