C# 如何设置;至;Vcalendar中的动态字段?

C# 如何设置;至;Vcalendar中的动态字段?,c#,asp.net,C#,Asp.net,在导出到Vcalendar时,我需要在“收件人”字段中设置登录用户的电子邮件地址 public static void ExportToIcalender(HttpContext ctx, DateTime startDate, DateTime endDate, string organizer, string location, string summary, string description) { string DateFormat = "yyyyMMddTHHmmssZ";

在导出到Vcalendar时,我需要在“收件人”字段中设置登录用户的电子邮件地址

public static void ExportToIcalender(HttpContext ctx, DateTime startDate, DateTime endDate, string organizer, string location, string summary, string description)
{
    string DateFormat = "yyyyMMddTHHmmssZ";
    ctx.Response.ClearContent();
    ctx.Response.ContentType = "text/calendar";
    ctx.Response.AddHeader("Content-disposition", "attachment; filename=appointment.ics");

    ctx.Response.Write("BEGIN:VCALENDAR");
    ctx.Response.Write("\nVERSION:2.0");
    ctx.Response.Write("\nMETHOD:PUBLISH");
    ctx.Response.Write("\nBEGIN:VEVENT");
    **ctx.Response.Write("\nORGANIZER:MAILTO:" + organizer);**

    ctx.Response.Write("\nDTSTART:" + startDate.ToUniversalTime().ToString(DateFormat));
    ctx.Response.Write("\nDTEND:" + endDate.ToUniversalTime().ToString(DateFormat));
    ctx.Response.Write("\nLOCATION:" + location);
    ctx.Response.Write("\nUID:" + DateTime.Now.ToUniversalTime().ToString(DateFormat) + "@mysite.com");
    ctx.Response.Write("\nDTSTAMP:" + DateTime.Now.ToUniversalTime().ToString(DateFormat));
    ctx.Response.Write("\nSUMMARY:" + summary);
    description = HtmlRemoval.StripTagsRegexCompiled(description).Replace("\r\n", "\\n");
    ctx.Response.Write("\nDESCRIPTION:" + description);
    ctx.Response.Write("\nPRIORITY:5");
    ctx.Response.Write("\nCLASS:PUBLIC");
    ctx.Response.Write("\nEND:VEVENT");
    ctx.Response.Write("\nEND:VCALENDAR");
    ctx.Response.End();
}
这句话对我没有帮助:

ctx.Response.Write("\nORGANIZER:MAILTO:" + organizer)

请提供解决方案。

您可以通过设置attendee属性来实现

ctx.Response.Write("\nATTENDEE;CN=someone@email.com;RSVP=TRUE:mailto:someone@email.com");

您可以通过设置attendee属性来实现这一点

ctx.Response.Write("\nATTENDEE;CN=someone@email.com;RSVP=TRUE:mailto:someone@email.com");

请修复格式。请修复格式。我应该使用ATTENDEE而不是ORGANIZER吗?如果要设置“是”字段,请选择“是”。尝试在outlook中创建约会,保存并在记事本中打开,然后自己查看。完美!!感谢您的快速回复好友。我应该使用ATTENDEE而不是ORGANIZER吗?如果要设置“是”字段,请选择“是”。尝试在outlook中创建约会,保存并在记事本中打开,然后自己查看。完美!!谢谢你的快速回复,伙计。