【发布时间】:2017-07-31 12:20:17
【问题描述】:
我在 asp.net 中有以下代码
GetObjectResponse resp = Media.ReadS3Object("data", strKey);
StreamReader sr = new StreamReader(resp.ResponseStream);
//Prompt download:
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = resp.ContentType; // "text/csv;";
HttpContext.Current.Response.AppendHeader("Content-Disposition", string.Format("attachment; filename={0}", fname));
HttpContext.Current.Response.BinaryWrite(UTF8Encoding.Convert(Encoding.UTF8, Encoding.Unicode, Encoding.UTF8.GetBytes(sr.ReadToEnd())));
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
它下载文件,我怎样才能通过mvc实现相同的功能。 谢谢
【问题讨论】:
-
您是否正在尝试将数据发布到服务器?看看这里:stackoverflow.com/questions/13963253/…
-
没有,我有文件路径,只是想下载
-
当您在 MVC 项目中尝试此代码时会发生什么?
-
你也可以看看这篇文章。 stackoverflow.com/questions/3604562/…
标签: c# asp.net-mvc