生成Icalendar文件(* .ICS)时遇到一些问题 我正在使用Ical.NET库和c#语言库。
代码非常简单,例如,这是VEVENT:
public override void HandleComponent(Ical.Net.Calendar root, CalendarData data)
{
var icalEvent = new Ical.Net.Event();
icalEvent.Start = new CalDateTime(data.Poczatek);
icalEvent.End = new CalDateTime(data.Koniec);
icalEvent.Location = data.Lokalizacja;
icalEvent.Description = data.Opis;
icalEvent.Summary = data.Nazwa;
root.Events.Add(icalEvent);
}
VJOURNEY和VTODO具有非常相似的代码<-首先,我正在创建组件,然后将其添加到日历对象中。
然后我从此代码生成了文件:
var serializer = new CalendarSerializer(calendar);
var icsContent = serializer.SerializeToString();
return icsContent;
ics文件的结构如下:
BEGIN:VCALENDAR
PRODID:-//github.com/rianjs/ical.net//NONSGML ical.net 2.2//EN
VERSION:2.0
BEGIN:VJOURNAL
ATTENDEE;CN=a;RSVP=TRUE;ROLE=REQ-PARTICIPANT:mailto:a@wp.pl
ATTENDEE;CN=a2;RSVP=TRUE;ROLE=REQ-PARTICIPANT:mailto:a2@wp.pl
DESCRIPTION:trele morele
DTSTAMP:20180913T072413Z
DTSTART:20180912T130700
ORGANIZER;CN=Administrator:mailto:Administrator@wp.pl
SEQUENCE:1
SUMMARY:qwerty22
UID:97032fa5-f554-4f10-9c4d-4fdda38148c7
END:VJOURNAL
END:VCALENDAR
就像规范中所说的:https://www.kanzaki.com/docs/ical/vjournal.html
问题:
Outlook 2016和GoogleCalender都只能使用ICalendar文件上的VEVENT组件正确处理。当我在GoogleCalendar中导入VJOURNAL或VTODO时,它回答说他没有发生任何事件... 难道我做错了什么?
我还将代码粘贴到我创建VJOURNAL的位置
public class CalendarJournalComponent : CalendarComponents
{
public override CalendarComponentType SupportedComponent => CalendarComponentType.Journal;
public override void HandleComponent(Ical.Net.Calendar root, CalendarData data)
{
var journal = new Journal();
journal.Start = new CalDateTime(data.Poczatek);
journal.Description = data.Opis;
journal.Summary = data.Nazwa;
if (data.Prowadzacy.Any())
{
var prowadzacy = data.Prowadzacy.FirstOrDefault();
journal.Organizer = new Organizer() { CommonName = prowadzacy.Value, Value = emailUri(prowadzacy.Key)};
}
journal.Attendees = new List<IAttendee>();
foreach(var uczesnik in data.Uczestnicy)
{
journal.Attendees.Add(new Attendee() { CommonName = uczesnik.Value, Rsvp = true, Value = emailUri(uczesnik.Key), Role = "REQ-PARTICIPANT" });
}
root.Journals.Add(journal);
}
private Func<string, Uri> emailUri = x => new Uri(String.Format("mailto:{0}", x));
}
和VTODO作曲
: public class CalendarTodoComponent : CalendarComponents
{
public override CalendarComponentType SupportedComponent => CalendarComponentType.ToDo;
public override void HandleComponent(Ical.Net.Calendar root, CalendarData data)
{
var todo = new Todo();
todo.Start = new CalDateTime(data.Poczatek);
todo.Description = data.Opis;
todo.Summary = data.Nazwa;
todo.Location = data.Lokalizacja;
root.Todos.Add(todo);
}
}
答案 0 :(得分:0)
您的代码很可能没问题。但是,您需要问自己,通过尝试将那些VJOURNAL和VTODO导入Google日历,您真正希望做什么? 从今天开始,Google日历实际上仅支持事件/会议: