您的位置:首页 > 其它

关于MVC将CSV格式文件保存到指定地址的BUG修正

2014-10-08 15:09 253 查看
前些天发的博文在本机测试的时候没有问题,经发布后,程序地址发生变化,导致不能正常完成导出,现修改程序如下:

前端:

function ExportOut() {

window.open('/StoreManage/Export');

};

后端代码:(当然是在Controllers中)

public FileContentResult Export()

{

System.IO.MemoryStream output = new System.IO.MemoryStream();

string excelstr = "title,address,longitude,latitude,coord_type,,AreaHead,StoreCorde,StoreRemarks,StoreDescription,StoreClass,StoreHead,StoreTel" + "\n";

var list = storeServices.LoadEntites(o =>o.IsDelete==false).ToList();

//输出内容

foreach (Store items in list)

{

string StoreAddress = string.IsNullOrEmpty(items.StoreAddress) ? "" : items.StoreAddress.Trim();

string StoreName = string.IsNullOrEmpty(items.StoreName) ? "" : items.StoreName.Trim();

string StoreTel1 = string.IsNullOrEmpty(items.StoreTel1) ? "" : items.StoreTel1.Trim();

excelstr +=

StoreName + "," +

StoreAddress + "," +

items.StoreLongitude + "," +

items.StoreLatitude + "," +

"3,," + //3:百度地理坐标加密方式

items.AreaHead + "," +

items.StoreCode + "," +

items.StoreRemarks + "," +

items.StoreDescription + "," +

items.StoreClass + "," +

items.StoreHead + "," +

StoreTel1 + "\n";

}

try

{

byte[] fileContent = System.Text.Encoding.GetEncoding("GB2312").GetBytes(excelstr);

return File(fileContent, "application/octet-stream", "门店信息.csv");

}

catch (Exception ex)

{

throw ex;

}

}

说明:要注意引用 IO空间
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐