gpt4 book ai didi

vb.net - 如何以编程方式创建 .ics 文件?

转载 作者:行者123 更新时间:2023-12-02 09:58:47 28 4
gpt4 key购买 nike

如何用最少的数据创建一个icalendar文件,我尝试将其制作如下,但出了问题,当我尝试导入到我的Google日历时,它说事件已成功导入,但我在日历上看不到这些事件

    strResult.Append("BEGIN:VCALENDAR" & vbCrLf)           

strResult.Append("VERSION:2.0" & vbCrLf)

strResult.Append("METHOD:PUBLISH" & vbCrLf)

While rst1.Read
strResult.Append("BEGIN:VEVENT" & vbCrLf)

strResult.Append("DTSTART: " & CDate(getLeave_date_start(CStr(rst1.getInteger("inq_id")), g_dom_id)).ToUniversalTime().ToString("yyyyMMddTHHmmssZ") & vbCrLf)

strResult.Append("DTEND: " & CDate(getLeave_date_end(CStr(rst1.getInteger("inq_id")), g_dom_id)).ToUniversalTime().ToString("yyyyMMddTHHmmssZ") & vbCrLf)

strResult.Append("SUMMARY: " & rst1.getString("inq_name") & vbCrLf)

strResult.Append("UID: " & rst1.getInteger("inq_id") & vbCrLf)

strResult.Append("CLASS:PUBLIC" & vbCrLf)

strResult.Append("END:VEVENT" & vbCrLf)

End While
strResult.Append("END:VCALENDAR" & vbCrLf)

WriteCalendar(strResult)

我编写了一个函数WriteCalendar,如下

Private Sub WriteCalendar(ByVal data As String)
Dim response As HttpResponse = Page.Response
response.Clear()
response.Buffer = True
response.ContentType = "text/calendar"
response.ContentEncoding = Encoding.UTF8
response.Charset = "utf-8"
response.AddHeader("Content-Disposition", "attachment;filename=""" & "icalendarTest" & ".ics""")
response.Write(data)
response.[End]()
End Sub

我下载了文件并查看了我的事件,但在导入到 Google 日历时,显示 6 个事件已成功导入,但我在日历上看不到它们

输出icalendarTest.ics

BEGIN:VCALENDAR  
VERSION:2.0
METHOD:PUBLISH
BEGIN:VEVENT
DTSTART: 20110107T060000Z
DTEND: 20110109T080000Z
SUMMARY: ayin yedisinden dokuzuna
UID: 9
CLASS:PUBLIC
END:VEVENT
BEGIN:VEVENT
DTSTART: 20110119T103000Z
DTEND: 20110119T150000Z
SUMMARY: tek gunluk ondokuz
UID: 10
CLASS:PUBLIC
END:VEVENT
BEGIN:VEVENT
DTSTART: 20110213T080000Z
DTEND: 20110213T160000Z
SUMMARY: Mijn Event
UID: 21
CLASS:PUBLIC
END:VEVENT
BEGIN:VEVENT
DTSTART: 20110301T083000Z
DTEND: 20110302T110000Z
SUMMARY: Mart kapidan baktirir
UID: 26
CLASS:PUBLIC
END:VEVENT
BEGIN:VEVENT
DTSTART: 20110117T080000Z
DTEND: 20110117T120000Z
SUMMARY: Neyse bi oncesi olsun
UID: 27
CLASS:PUBLIC
END:VEVENT
BEGIN:VEVENT
DTSTART: 20110121T130000Z
DTEND: 20110121T180000Z
SUMMARY: ocak 21i
UID: 31
CLASS:PUBLIC
END:VEVENT
END:VCALENDAR

最佳答案

我没有在 .ics 中包含所有标签,这就是此错误的原因。

我从 Google 日历中提取了自己的日历并添加了缺失的数据,现在它可以工作了。 DTSTAMP 似乎是必需的,尽管我发现这是不必要的,但只要它有效就可以了

    strResult.Append("BEGIN:VCALENDAR" & vbCrLf)
strResult.Append("PRODID:-//Google Inc//Google Calendar 70.9054//EN" & vbCrLf)
strResult.Append("VERSION:2.0" & vbCrLf)
strResult.Append("METHOD:PUBLISH" & vbCrLf)

While rst1.Read
strResult.Append("BEGIN:VEVENT" & vbCrLf)
strResult.Append("DTSTART:" & rst1.getDateTime("hly_startdate").ToUniversalTime().ToString("yyyyMMddTHHmmssZ") & vbCrLf)
strResult.Append("DTEND:" & rst1.getDateTime("hly_enddate").ToUniversalTime().ToString("yyyyMMddTHHmmssZ") & vbCrLf)
strResult.Append("DTSTAMP:" & rst1.getDateTime("hly_date_created").ToUniversalTime().ToString("yyyyMMddTHHmmssZ") & vbCrLf)
strResult.Append("SEQUENCE:0" & vbCrLf)
strResult.Append("STATUS:CONFIRMED" & vbCrLf)
strResult.Append("SUMMARY:" & rst1.getString("hly_name") & vbCrLf)
strResult.Append("UID:" & System.Guid.NewGuid.ToString() & vbCrLf)
strResult.Append("CLASS:PUBLIC" & vbCrLf)
strResult.Append("TRANSP:OPAQUE" & vbCrLf)
strResult.Append("END:VEVENT" & vbCrLf)

End While
strResult.Append("END:VCALENDAR" & vbCrLf)

关于vb.net - 如何以编程方式创建 .ics 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4931316/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com