471,321 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,321 software developers and data experts.

extract blob from database

I would like to be able to extract a BLOB from the database (SqlServer)
and pass it to a browser without writing it to a file. (The BLOB's
are word doc's, MS project doc's, and Excel spreadsheets.

How can I do this?
Nov 15 '05 #1
3 3618
Hello,

I can help you with the first bit, extracting the blob from the database.

Create a SqlCommand to select it, e.g. "SELECT Blob FROM DataTable WHERE
<some criteria>". Then use ExecuteScalar to retrieve the result and cast it
to a byte array:
byte[] blob = (byte[])cmd.ExecuteScalar();

But I don't know what you need to do next, sorry. I'm sure somebody else
will know.
"Selen" <sk*****@yahoo.com> wrote in message
news:uE**************@TK2MSFTNGP11.phx.gbl...
I would like to be able to extract a BLOB from the database (SqlServer)
and pass it to a browser without writing it to a file. (The BLOB's
are word doc's, MS project doc's, and Excel spreadsheets.

How can I do this?

Nov 15 '05 #2
Response.Clear();
Response.AddHeader( "content-disposition", "attachment;
filename=\"Stuff.doc\"");
Response.ContentType = "application/msword";
// (or whatever the appropriate MIIME type)
Response.BinaryWrite( blob); // your byte array

// above is untested but you get the idea...
Your choices are "inline" or "attachment". If you choose "inline" then the
response
may be displayed in the browser if it so chooses
depending on the setting of the ContentType. If you choose "attachment" the
user will
always be prompted to save or open.

"Selen" <sk*****@yahoo.com> wrote in message
news:uE**************@TK2MSFTNGP11.phx.gbl...
I would like to be able to extract a BLOB from the database (SqlServer)
and pass it to a browser without writing it to a file. (The BLOB's
are word doc's, MS project doc's, and Excel spreadsheets.

How can I do this?

Nov 15 '05 #3
Response.Clear();
Response.AddHeader( "content-disposition", "attachment;
filename=\"Stuff.doc\"");
Response.ContentType = "application/msword";
// (or whatever the appropriate MIIME type)
Response.BinaryWrite( blob); // your byte array

// above is untested but you get the idea...
Your choices are "inline" or "attachment". If you choose "inline" then the
response
may be displayed in the browser if it so chooses
depending on the setting of the ContentType. If you choose "attachment" the
user will
always be prompted to save or open.

"Selen" <sk*****@yahoo.com> wrote in message
news:uE**************@TK2MSFTNGP11.phx.gbl...
I would like to be able to extract a BLOB from the database (SqlServer)
and pass it to a browser without writing it to a file. (The BLOB's
are word doc's, MS project doc's, and Excel spreadsheets.

How can I do this?

Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by John | last post: by
5 posts views Thread by Bob Kaku | last post: by
6 posts views Thread by Juergen Gerner | last post: by
3 posts views Thread by hamvil79 | last post: by
9 posts views Thread by Hrvoje Voda | last post: by
6 posts views Thread by Selen | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.