0
我的两难境地是我需要检索存储在oracle中的表中的blob数据。我已经创建了与使用jquery的数据链接,链接到一个通用的http处理程序blobHandler.ashx,其中我查询数据库中的文件并将其返回给用户。 这适用于在浏览器中打开的图像,但对于其他文件类型(pdf,word,excel),该程序仅下载.ashx文件本身。如何使用通用http处理程序在C#中下载一个随机文件类型的blob
我如何得到它下载文件的扩展名?
using (OracleConnection objConn = new OracleConnection(conStr))
{
using (OracleCommand cmd = new OracleCommand())
{
cmd.Connection = objConn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT fl.file_content_type, fl.file_data,fl.file_name FROM fnd_lobs fl WHERE fl.file_id = " + mediano;
try
{
objConn.Open();
OracleDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
OracleBlob blob = dr.GetOracleBlob(1);
FileStream FS = new FileStream(dr["file_name"].ToString(), FileMode.Create);
Byte[] byteArr = new Byte[blob.Length];
int i = blob.Read(byteArr,0,System.Convert.ToInt32(blob.Length));
MemoryStream memStream = new MemoryStream(byteArr);
context.Response.AddHeader("Content-disposition: inline", "attachment; filename=" + dr["file_name"]);
context.Response.ContentType = dr["file_content_type"].ToString();
context.Response.OutputStream.Write(byteArr,0,i);
}
}
}
catch(Exception exe)
{
context.Response.Write(exe.Message);
}
finally
{
cmd.Dispose();
//pcur.Dispose();
objConn.Close();
objConn.Dispose();
context.Response.Flush();
context.Response.End();
}
}
}
我使用 的.NET Framework 1.1, Visual Studio 2003中, Oracle数据库版本10.3.0.5
预先感谢您的任何建议您可以提供,这是我在这里的第一个问题。
感谢您的回复,我做了您建议的更改,现在我得到了“访问拒绝”的消息。你有没有经历过类似的事情? –
user2359298
2013-05-07 18:43:58
请更新您的问题,修改 – tucaz 2013-05-07 23:59:46
以包含请求的数据。 – user2359298 2013-05-08 15:46:59