文件是空的,我不明白为什么。 Asp.net mvc 文件结果
我正在尝试使用内置的 asp.net 文件结果返回我试图通过文件流创建的文件。我正在使用 Dday.ical 制作要导出的日历
MemoryStream export = new MemoryStream();
iCalendarSerializer serializer = new iCalendarSerializer(iCal);
serializer.Serialize(export,System.Text.Encoding.Default);
return export;
这是我的 actionResult
public ActionResult ExportCalendar()
{
string userName = User.Identity.Name;
Guid userId = membershipS.GetUsersId(userName);
var calendarStream = calendarS.ExportCalendar(userId);
return File(calendarStream, "text/calendar", "test.ics");
}
当我下载文件时,它是 0 字节。
I am trying to use the built in asp.net file result to return a file that I am trying to make through a file stream. I am using Dday.ical to make my calendar for export
MemoryStream export = new MemoryStream();
iCalendarSerializer serializer = new iCalendarSerializer(iCal);
serializer.Serialize(export,System.Text.Encoding.Default);
return export;
Here is my actionResult
public ActionResult ExportCalendar()
{
string userName = User.Identity.Name;
Guid userId = membershipS.GetUsersId(userName);
var calendarStream = calendarS.ExportCalendar(userId);
return File(calendarStream, "text/calendar", "test.ics");
}
When I download the file it is 0bytes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试重置流的位置:
这样,当 FileResult 开始从流中读取时,它将从头开始而不是从末尾读取(之后显然没有更多字节了!)。
Try resetting the stream's position:
That way when the
FileResult
starts reading from the stream it will read it from the beginning instead of from the end (after which there are obviously no more bytes!).