4

I am Creating ICS file fromC# WPF application and using the following code to generate ICS file.

StreamWriter writer;
writer = new StreamWriter(filePath);
writer.WriteLine("BEGIN:VCALENDAR");
writer.WriteLine("VERSION:2.0");
writer.WriteLine("PRODID:MyApp");
writer.WriteLine("CALSCALE:GREGORIAN");
writer.WriteLine("METHOD:PUBLISH");
writer.WriteLine("BEGIN:VEVENT");
string startDateTime = Convert.ToDateTime(appointmentDetails.StartDate).ToString("yyyyMMdd'T'HHmmss");
string endDateTime = Convert.ToDateTime(appointmentDetails.EndDate).ToString("yyyyMMdd'T'HHmmss");

writer.WriteLine("DTSTART:" + startDateTime);
writer.WriteLine("DTEND:" + endDateTime);
writer.WriteLine(@"DESCRIPTION:" + appointmentDetails.Body);
writer.WriteLine("SUMMARY:" + appointmentDetails.Subject);
writer.WriteLine("END:VEVENT");
writer.WriteLine("END:VCALENDAR");
writer.Close();

But I have some problems while fromating the description.I think when I add \n for new line ,it creates a problem. I need to format my string like this.

------------------
Header1
-----------------
bOdy1
contents
---------------

I am using the following line to create a dotted line.

result += new String('-', characterLength) + "\\n";

But the out put showing one line instead of dotted line.I think “\n” creates the problem.when I add some space after the new line escape character I can see the problem solved.Is there any better/alternate solution for this?

Some string in the description showing in different font style.How can Make it unique?

How can I set the font for this ICs file from the C#?

Please suggest.

4

2 回答 2

0

首先:您应该尝试找到一个 iCalendar 库,而不是自己编写。格式非常复杂,您可能缺少很多小东西。

每行最多应为 75 个字节左右。如果一行不合适(因为它更大),您可以通过注入一个真正的换行符 ( \r\n) 后跟一个空格或制表符来拆分该行。

iCalendar 阅读器将简单地删除任何\r\n[space]\r\n\t

不过,您必须确保不会在多字节 UTF-8 序列的中间破坏文件。

描述的值必须这样编码:

  • ;必须成为\;
  • ,必须成为\,
  • 任何换行必须成为文字\n\N

这有帮助吗?如果没有,请发布您的 iCalendar 流的完整输出,以便我可以告诉您哪里出错了。

于 2013-05-18T20:06:47.123 回答
-1

格式说明...

    str.AppendLine(String.Format("DESCRIPTION:{0}", description));
    str.AppendLine(String.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", description));
于 2017-06-05T04:05:06.580 回答