开发者

Windows Phone 7 - iCal Generator - C#

I need to generate iCal string from appointments开发者_JS百科 fetched from device. Is there any library that is supported on Windows Phone 7 to generate iCal from appointments?

I tried DDay.iCal, but it does not work with Windows Phone 7.


There isn't a library specific for Windows Phone 7 I've come across, but it shouldn't be too difficult to write your own classes to generate iCal files, since iCal is just text, after all. The RFC is quite a dense read, but using some online references like this one and looking at some example iCal files should be enough to get started. Take this example iCal file from wikipedia, for example:

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:uid1@example.com
DTSTAMP:19970714T170000Z
ORGANIZER;CN=John Doe:MAILTO:john.doe@example.com
DTSTART:19970714T170000Z
DTEND:19970715T035959Z
SUMMARY:Bastille Day Party
END:VEVENT
END:VCALENDAR

So note you BEGIN and END a VCALENDAR, and a VEVENT within them, which has some required fields (like the UID). The only thing to note is that the specification requires lines longer than 75 octets to be broken up, so you can use this method from this stack overflow question for fields with long text:

Private Function RFC2445TextField(ByVal LongText As String) As String

     LongText = LongText.Replace("\", "\\")
     LongText = LongText.Replace(";", "\;")
     LongText = LongText.Replace(",", "\,")


     Dim sBuilder As New StringBuilder
     Dim charArray() As Char = LongText.ToCharArray

     For i = 1 To charArray.Length
         sBuilder.Append(charArray(i - 1))
         If i Mod 74 = 0 Then sBuilder.Append(vbCrLf & " ")
     Next

     Return sBuilder.ToString

 End Function

The function basically escapes all required escape characters, and inserts a linefeed/space every 74 characters.

Good luck, have fun! :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜