Hi all, I'm trying to display a word document in my asp.net page which had been saved in Access database 2003 as an OleDb Object. If I'm not mistaken the process is the same as retrieving and displaying an image from the database. I've found a snippet of code online for retrieving doing just that and have tried to study it to understand how it works. This is what I understand from looking at the code:
1 Grab the id of the file you want to display from the database using a sql statement
2 Grab the content type of the file you want using a sql statement
3 Read the BLOB value using the ExecuteScalar() method of the SqlCommand class.
4 Cast the return object to byte array and store it in byte array because
executeScalar() returns an object.
5 Stream it back to the HTTP response
The following is the code snippet I'm trying to use:
void CreateImage(string id)
{
SqlConnection _con = new SqlConnection(
System.Configuration.ConfigurationSettings.AppSettings["DB"]);
try
{
_con.Open();
SqlCommand _cmd = _con.CreateCommand();
_cmd.CommandText = "select logo from" +
" pub_info where pub_id='" +
id + "'";
byte[] _buf = (byte[])_cmd.ExecuteScalar();
Response.ContentType = "image/gif";
Response.BinaryWrite(_buf);
}
catch
{}
finally
{
_con.Close();
}
}
In the Page_Load(), call CreateImage method.
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
CreateImage(Request["id"]);
}
}
Then use
<img src='<%# "imgs.aspx?id=" + drpIds.SelectedValue %>'>
to display image
Finally call
Page.databind.
My question is how can I modify the step
<img src='<%# "imgs.aspx?id=" + drpIds.SelectedValue %>'>
to display a word doc in a text field. Thanks in advance for your help.