2017-09-19 29 views
0

我正在嘗試創建日曆邀請並希望在附加的ICS文件中添加HTML內容。在ICS文件中爲Outlook預約添加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", "[email protected]"))); 

    a.Append((string.Format("ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=FALSE;X-NUM-GUESTS=0:mailto:{0}\r\f", "[email protected]"))); 


    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; 
} 

誰能請就如何實現這一目標的一些投入?

在此先感謝。

回答

0

我終於設法解決了這個問題。 請找到解決辦法如下: -

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; 
} 

注: -我已經在「Sample.html」文件在保存前再縮小HTML。

希望它可以幫助別人!

相關問題