c# - 在 Outlook 约会的 ICS 文件中添加 HTML

标签 c# asp.net outlook calendar icalendar

我正在尝试创建日历邀请,并希望在附加的 ICS 文件中添加 HTML 内容。

以下代码不起作用:-

private static byte[] CreateiCal(int current_sequence, string guid, string subject, string location, DateTime startTime, DateTime endTime)
    {
    var a = new StringBuilder();
    var sb = new StringBuilder();
    a.Append("BEGIN:VCALENDAR\r\f");
    a.Append("VERSION:2.0\r\f");
    a.Append("PRODID:-//ince/events//NONSGML v1.0//EN\r\f");
    a.Append("TZ:+00\r\f");
    a.Append("BEGIN:VEVENT\r\f");
    a.Append(String.Format("SEQUENCE:{0}\r\f", sequence.ToString()));
    a.Append(String.Format("DTSTART:{0}\r\f", GetFormatedDate(startTime)));
    a.Append(String.Format("DTEND:{0}\r\f", GetFormatedDate(endTime)));
    a.Append(String.Format("LOCATION:{0}\r\f", location));
    a.Append(String.Format("UID:{0}\r\f", guid));
    a.Append(String.Format("SUMMARY:{0}\r\f", subject));

    sb.Append("Sample Text1 \n");
    sb.Append("Sample Text2 \n");
    sb.Append(string.Format("Sample Text3 <a href='{0}'>LINK</a> \n", "www.google.com"));
    sb.Append("Sample Text4 \n");

    a.Append(String.Format("DESCRIPTION;X-ALT-DESC;FMTTYPE=text/html:"+sb.ToString() + "\r\f"));

    a.Append((string.Format("ORGANIZER:MAILTO:{0}\r\f", "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="610c00080d282521020e13110e130015044f020e0c" rel="noreferrer noopener nofollow">[email protected]</a>")));

    a.Append((string.Format("ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=FALSE;X-NUM-GUESTS=0:mailto:{0}\r\f", "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7914181015303d4b391a160b09160b180d1c571a1614" rel="noreferrer noopener nofollow">[email protected]</a>")));


    a.Append(String.Format("X-MICROSOFT-CDO-APPT-SEQUENCE:{0}\r\f", current_sequence.ToString()));

    a.Append("BEGIN:VALARM\r\f");
    a.Append("TRIGGER:-PT15M\r\f");
    a.Append("REPEAT:2\r\f");
    a.Append("DURATION:PT15M\r\f");
    a.Append("ACTION:DISPLAY\r\f");
    a.Append("DESCRIPTION:Reminder\r\f");
    a.Append("END:VALARM\r\f");
    a.Append("END:VEVENT\r\f");
    a.Append("END:VCALENDAR\r\f");
    byte[] b = Encoding.ASCII.GetBytes(a.ToString());
    return b;
}

任何人都可以分享一些关于如何实现这一目标的意见吗?

提前致谢。

最佳答案

我终于成功解决了这个问题。 请在下面找到解决方案:-

private static byte[] CreateiCal(int current_sequence, string guid, string subject, string location, DateTime startTime, DateTime endTime)
{

            var a = new StringBuilder();
            int sequence = current_sequence + 1;

            a.Append("BEGIN:VCALENDAR\r\f");
            a.Append("VERSION:2.0\r\f");
            a.Append("PRODID:-//ince/events//NONSGML v1.0//EN\r\f");

            a.Append("TZ:+00\r\f");
            a.Append("BEGIN:VEVENT\r\f");
            a.Append(String.Format("SEQUENCE:{0}\r\f", sequence.ToString()));
            a.Append(String.Format("DTSTART:{0}\r\f", GetFormatedDate(startTime)));
            a.Append(String.Format("DTEND:{0}\r\f", GetFormatedDate(endTime)));
            a.Append(String.Format("LOCATION:{0}\r\f", location));
            a.Append(String.Format("UID:{0}\r\f", guid));

            a.Append(String.Format("SUMMARY:{0}\r\f", subject));

            string desc = File.ReadAllText("Sample.html", Encoding.GetEncoding("iso-8859-1")); // iso-8859-1 : HTML contains French characters

            a.Append("X-ALT-DESC;FMTTYPE=text/html:" + desc + "\r\f");

            a.Append(String.Format("DESCRIPTION:{0}\r\f", desc));


            a.Append(String.Format("X-MICROSOFT-CDO-APPT-SEQUENCE:{0}\r\f", current_sequence.ToString()));

            a.Append("BEGIN:VALARM\r\f");
            a.Append("TRIGGER:-PT15M\r\f");
            a.Append("REPEAT:2\r\f");
            a.Append("DURATION:PT15M\r\f");
            a.Append("ACTION:DISPLAY\r\f");
            a.Append("DESCRIPTION:Reminder\r\f");

            a.Append("END:VALARM\r\f");
            a.Append("END:VEVENT\r\f");


            a.Append("END:VCALENDAR\r\f");

            byte[] b = Encoding.UTF8.GetBytes(a.ToString());

            return b;
}

注意:- 在将 HTML 保存到“Sample.html”文件中之前,我必须缩小 HTML。

希望对其他人有帮助!!

关于c# - 在 Outlook 约会的 ICS 文件中添加 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46292756/

相关文章:

c# - 使用与正在运行的应用程序相同的凭据打开 Outlook

css - Outlook 中的表格宽度过大

c# - 计算列表父实体的子实体的总和

c# - 计算非常大的整数

c# - 确定应用程序根目录的最佳方法是什么?

c# - 将文本发送到另一个客户端的浏览器有哪些漏洞?

c# - 我应该用数据传输对象包装实体吗

c# - 如何在新的 Microsoft 图表控件中为数据点添加垂直线

c# - Selenium 无法连接到本地主机以测试 ASP.NET

excel - 即使缺少预期的附件,如何生成电子邮件?