【发布时间】:2012-11-25 15:53:50
【问题描述】:
我正在尝试创建 Outlook 日历活动,但我的部分文本在 Outlook 中消失了。
private List<ICalEvent> _events;
public override void ExecuteResult(System.Web.Mvc.ControllerContext context)
{
StringBuilder str = new StringBuilder();
var _with1 = str;
foreach (var _event in _events)
{
_with1.AppendLine("BEGIN:VCALENDAR");
_with1.AppendLine("VERSION:2.0");
_with1.AppendLine("BEGIN:VEVENT");
_with1.AppendLine(string.Format("DTSTART:{0}", _event.start.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z")));
_with1.AppendLine(string.Format("DTEND:{0}", _event.end.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z")));
_with1.AppendLine(string.Format("SUMMARY:{0}", _event.summary));
_with1.AppendLine(string.Format("DESCRIPTION:{0}", _event.description));
_with1.AppendLine(string.Format("LOCATION:{0}", _event.location));
_with1.AppendLine("END:VEVENT");
_with1.AppendLine("END:VCALENDAR");
}
context.HttpContext.Response.ContentType = "text/calendar";
context.HttpContext.Response.AddHeader("Content-disposition", string.Format("attachment; filename={0}", "newFile"));
context.HttpContext.Response.Write(str.ToString());
}
当我在description 中有多行时会出现问题。例如,如果它包含文本 "New\r\nLine",我只会在 Outlook 日历描述中看到“New”。 "\r\n" 之后的部分消失了。
我已经尝试了所有这些但结果相同:
_event.description.Replace("\r\n", "\n\n")_event.description.Replace("\\", "\\\\")_event.description.Replace("\r\n", Environment.NewLine)
有人遇到过类似的问题吗?
【问题讨论】:
-
尝试使用_event.description.Replace("\r\n","
") -
@Frank59 这将打印“New
Line”,但实际上不会在 Outlook 中换行。
标签: c# outlook newline icalendar