V120703 - 匯入格式下載
目的: 提供使用者由資料庫下載匯入格式(SS_FILES. FNAME + FBODY)
1>[匯入格式下載]鈕 *.js
{
xtype: 'button', text: '匯入格式下載', id: 'DownFmtBtn',
handler: function () {
document.location = "../api/VUTLAPI/dnloadSS_File?FNAME=V120503_匯入格式下載.xls ";
} // end of handler
*.cs
public bool dnloadSS_FileS(string FNAME)
{
string Strsql = "select FNAME,FBODY from SS_FILES where FNAME = '" + FNAME + "' ";
try
{ downloadFile(Strsql, "FNAME", "FBODY"); }
catch (Exception ex)
{ throw ex; }
finally { }
return true;
}
public byte[] downloadFile(string sql, string fileName, string fileBody)
{
setActionName();
OracleConnection conn = new OracleConnection(DBService.ConnectionString(DBLINK));
conn.Open();
conn.ClientInfo = User.Identity.Name;
conn.ModuleName = BaseSYS + "_" + BaseMODID;
conn.ActionName = ActionName;
OracleCommand cmd = new OracleCommand(sql, conn);
OracleDataReader reader = cmd.ExecuteReader();
byte[] file = null;
if (reader.Read())
{
try
{
//clearing the content
HttpContext.Current.Response.ClearContent();
// adding the headers to file stream
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=\"" + HttpUtility.UrlEncode((string)reader[fileName], System.Text.Encoding.UTF8) + "\"");
//BinaryWriter bw = new BinaryWriter(HttpContext.Current.Response.OutputStream);
// converting data into bytes
file = (byte[])reader[fileBody];
//bw.Write(file);
//bw.Close();
HttpContext.Current.Response.BinaryWrite(file);
HttpContext.Current.Response.End();
}
finally
{
reader.Close();
conn.Close();
}
}
return file;
}
沒有留言:
張貼留言