问题描述
privatevoidOutPutCsv(Stringcsv,stringdownFile){using(StringWriterms1=newStringWriter()){ms1.Write(csv);HttpContextcurContext=HttpContext.Current;//设置编码和附件格式curContext.Response.Clear();curContext.Response.ContentType="application/vnd.ms-text";//"application/vnd.ms-excel";curContext.Response.ContentEncoding=Encoding.UTF8;curContext.Response.Charset="GB2312";if(Request.UserAgent.Contains("MSIE")||Request.UserAgent.Contains("msie")){curContext.Response.AppendHeader("Content-Disposition","attachment;filename="+HttpUtility.UrlEncode(downFile,Encoding.UTF8));}else{curContext.Response.AppendHeader("Content-Disposition","attachment;filename="+downFile);}curContext.Response.Write(ms1);curContext.Response.End();}}高手看看这样行不行(本机csv默认设置为excel,下载后还是用excel),本人想下载后的csv默认让记事本打开
解决方案
解决方案二:
csv由什么打开是客户端操作系统决定的,和contenttype无关。你可以把后缀由csv修改为txt看看