[CheckSession]
public ActionResult ExpDataTwo()
{
try
{
string Status_Missionn = Request.QueryString["sexch"];
ParadoxWebService.ParadoxServiceClient client = new ParadoxWebService.ParadoxServiceClient();
ExportResultInfo res = client.ExportParadoxDataBase(LoadExportSqlStrTwo(Status_Missionn), "GLJ");
string XMlDirectory = System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/Download/");
string fileName = Session["hangji"].ToString() + Session["atmTwo_Code"].ToString() + DateTime.Now.ToString("yyyyMMddmmss") + ".DB"; // 以分秒为文件名。
# region 处理乱码
Encoding encoding;
string outputFileName = null;
string browser = Request.UserAgent.ToUpper();
if (browser.Contains("MS") == true && browser.Contains("IE") == true)
{
outputFileName = HttpUtility.UrlEncode(fileName, Encoding.UTF8).Replace("+", "%20");
encoding = System.Text.Encoding.Default;
}
else if (browser.Contains("FIREFOX") == true)
{
outputFileName = fileName;
encoding = System.Text.Encoding.GetEncoding("GB2312");
}
else
{
outputFileName = HttpUtility.UrlEncode(fileName);
encoding = System.Text.Encoding.Default;
}
#endregion
string url = XMlDirectory + fileName;
ConvertToDB(res.ExportDbBuffer, url);
return File(url, "application/vnd.borland", outputFileName);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 字节转化为文件。
/// </summary>
/// <param name="buffer"></param>
private void ConvertToDB(byte[] buffer, string filePath)
{
FileStream fstream = System.IO.File.Create(filePath, buffer.Length);
try
{
fstream.Write(buffer, 0, buffer.Length);
}
catch (Exception ex)
{
}
finally
{
fstream.Close();
}
}