HttpRequest request = System.Web.HttpContext.Current.Request;
string baseUrl = request.Url.GetLeftPart(UriPartial.Authority);
var hLink = string.Format("{0}/Activities/Details?id={1}", baseUrl, responseDto.Id);
var sb = new StringBuilder();
sb.Append(@"X-ALT-DESC;FMTTYPE=text/html:<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 3.2//EN"">\n<HTML><BODY>");
sb.Append(string.Format("<a href=\"{0}\">{1}</a>", hLink, responseDto.Notes));
sb.Append("</BODY></HTML>");
using (var memoryStream = new MemoryStream())
{
using (var writer = new StreamWriter(memoryStream))
{
writer.AutoFlush = true;
//HEADER
writer.WriteLine("BEGIN:VCALENDAR");
writer.WriteLine("VERSION:1.0");
writer.WriteLine("BEGIN:VEVENT");
//BODY
writer.WriteLine("DTSTART:" + responseDto.Date.ToUniversalTime().ToString("o"));
writer.WriteLine("DTEND:" + responseDto.Date.AddHours(1).ToUniversalTime().ToString("o"));
writer.WriteLine("SUMMARY:" + responseDto.ActivityType.Name);
writer.WriteLine("DESCRIPTION:" + sb.ToString());
//writer.WriteLine("LOCATION:" + responseDto.Location);
//FOOTER
writer.WriteLine("END:VEVENT");
writer.WriteLine("END:VCALENDAR");
writer.Flush();
contentData = new byte[(int)memoryStream.Length];
memoryStream.Position = 0;
memoryStream.Read(contentData, 0, (int)memoryStream.Length);
return contentData;
}
}
正在创建文件,但链接未显示,而是在描述中呈现sb的全部内容:
X-ALT-DESC;FMTTYPE=text/html:<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 3.2//EN”>
<HTML><BODY><a href=”http://localhost:58999/Activities/Details?id=5d018f0f-b45b-4797-8404-fb8bbf31331d”>Redwings</a></BODY></HTML>
我是C#和HTML的新手,所以任何输入都会有所帮助。
由于
答案 0 :(得分:0)
由于格式化,这很难理解。
正在创建文件,但链接未显示,而是在描述中呈现sb的全部内容:
我没有看到您将 MemoryStream 中的contentData
传递到StringBuilder中的任何地方。
是否缺少某些代码?
答案 1 :(得分:0)
该行必须
DESCRIPTION;X-ALT-DESC;FMTTYPE=text/html:<html><body><a href="http://localhost:58999/Activities/Details?id=5d018f0f-b45b-4797-8404-fb8bbf31331d”>My link</a></body></html>
必须有&#34 ;;&#34;,而不是&#34;:&#34;在描述之后,您的HTML必须有效,而不仅仅是网址。