asp.net mvc return file result

  asp.net mvc返回文件:

public ActionResult ExportReflection(string accessToken)
        {
            var reflections = GetCmsReflectionList(accessToken);

            var sb = new StringBuilder();
            sb.AppendFormat("{0,-10},{1,-10},{2,-10},{3,-10},{4,-10},{5,-100},{6,-100},{7,-50}", "创建者身份", "创建者姓名", "教练打分", "所属能力", "主题", "内容", "参与者", "创建时间");
            sb.AppendLine();
            foreach (var r in reflections)
            {
                var creatorRole = r.CreatorRole == 0?"学员":"教练";
                sb.AppendFormat("{0,-10},{1,-10},{2,-10},{3,-10},{4,-10},{5,-100},{6,-100},{7,-50}", 
                    creatorRole, 
                    r.CreatorUserName,
                    r.ScoreFromCoach,
                    r.CompetencyName,
                    r.Subject,
                    r.Content,
                    r.ParticipantsNameString,
                    r.CreatedTime);
                sb.AppendLine();
            }
            //var encoding = Encoding.GetEncoding(936); //gb2312
            var bytes = Encoding.GetEncoding(936).GetBytes(sb.ToString());

            //return File(new MemoryStream(bytes, 0, bytes.Length), "application/csv", "reflections" + DateTime.UtcNow.ToShortDateString() + ".csv");//excel打开csv有乱码
            return File(bytes, "application/csv", "reflections" + DateTime.UtcNow.ToShortDateString() + ".csv");
        }

 

asp.net mvc return file result,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。