By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,353 Members | 1,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,353 IT Pros & Developers. It's quick & easy.

Stream blob data to a tiff format

P: n/a
Hi I have an issue when trying to stream blob image data from a SQL table to
a .aspx page. the code I have works for GIF and JPEG but the images can be
multiple pages and we would like them to open in a TIFF format.

What comes back to the screen is garble.... Can anyone help? Thanks

The code I am using is:

SqlConnection myConn = new
SqlConnection(ConfigurationSettings.AppSettings["strConnection"]);
SqlCommand myComm = new SqlCommand("Select SX_Image_Data from
SX_ACCSXDB_Images where chrBarCode = '" + Request.QueryString["invoice"] +
"'",myConn);

myConn.Open();
try
{
byte [] img = (byte[]) myComm.ExecuteScalar();
MemoryStream ms = new MemoryStream();
ms.Write(img, 0, img.Length);
Bitmap bmp = new Bitmap(ms);

bmp.Save(Response.OutputStream, ImageFormat.Tiff);

}
catch(Exception)
{
Response.Write("<center><h4>The Invoice you are requesting does not
exist in the system</h4></center>");
}
Nov 16 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Phil <Ph**@discussions.microsoft.com> wrote:
Hi I have an issue when trying to stream blob image data from a SQL table to
a .aspx page. the code I have works for GIF and JPEG but the images can be
multiple pages and we would like them to open in a TIFF format.

What comes back to the screen is garble.... Can anyone help? Thanks


I can't see anything there setting the content type - have you tried
that?

What happens if you save the output to disk and load it from explorer?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2

P: n/a
Phil,

Are you setting the mime type correctly for the image? If the image is
in TIFF format (something that might not be able to be "sniffed" as easily),
then the browser might very well show it as garbage (especially if the
returned mime type says it is something else).

Also, your logic should be changed to show that the invoice does not
exist if the return value is null, not if an exception is thrown. An
exception might be thrown for any number of other reasons in your code,
while the invoice might actually exist. It is misleading, and the idea of
basing business logic on exception handling is generally a bad one (hard to
maintain, etc, etc).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Phil" <Ph**@discussions.microsoft.com> wrote in message
news:14**********************************@microsof t.com...
Hi I have an issue when trying to stream blob image data from a SQL table
to
a .aspx page. the code I have works for GIF and JPEG but the images can be
multiple pages and we would like them to open in a TIFF format.

What comes back to the screen is garble.... Can anyone help? Thanks

The code I am using is:

SqlConnection myConn = new
SqlConnection(ConfigurationSettings.AppSettings["strConnection"]);
SqlCommand myComm = new SqlCommand("Select SX_Image_Data from
SX_ACCSXDB_Images where chrBarCode = '" + Request.QueryString["invoice"] +
"'",myConn);

myConn.Open();
try
{
byte [] img = (byte[]) myComm.ExecuteScalar();
MemoryStream ms = new MemoryStream();
ms.Write(img, 0, img.Length);
Bitmap bmp = new Bitmap(ms);

bmp.Save(Response.OutputStream, ImageFormat.Tiff);

}
catch(Exception)
{
Response.Write("<center><h4>The Invoice you are requesting does not
exist in the system</h4></center>");
}

Nov 16 '05 #3

P: n/a
Native TIFF support is not present in either Microsoft Internet Explorer
nor Mozilla FireFox.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Phil <Ph**@discussions.microsoft.com> wrote:
Hi I have an issue when trying to stream blob image data from a SQL table
to
a .aspx page. the code I have works for GIF and JPEG but the images can
be
multiple pages and we would like them to open in a TIFF format.

What comes back to the screen is garble.... Can anyone help? Thanks


I can't see anything there setting the content type - have you tried
that?

What happens if you save the output to disk and load it from explorer?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #4

P: n/a
I have tried Response.ContentType = "image/tiff"; and this prompts me to open
the document then a dialog box appears saying:

"The file referenced by the shortcut file blablabla\blablabla\Temp Internet
Files\Content.IE5\blablabla\requestInvoice[1].aspx cannot be opened"

I will also work on the logic once I get the file to open properly.. thanks
for the tip there.

"Nicholas Paldino [.NET/C# MVP]" wrote:
Phil,

Are you setting the mime type correctly for the image? If the image is
in TIFF format (something that might not be able to be "sniffed" as easily),
then the browser might very well show it as garbage (especially if the
returned mime type says it is something else).

Also, your logic should be changed to show that the invoice does not
exist if the return value is null, not if an exception is thrown. An
exception might be thrown for any number of other reasons in your code,
while the invoice might actually exist. It is misleading, and the idea of
basing business logic on exception handling is generally a bad one (hard to
maintain, etc, etc).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Phil" <Ph**@discussions.microsoft.com> wrote in message
news:14**********************************@microsof t.com...
Hi I have an issue when trying to stream blob image data from a SQL table
to
a .aspx page. the code I have works for GIF and JPEG but the images can be
multiple pages and we would like them to open in a TIFF format.

What comes back to the screen is garble.... Can anyone help? Thanks

The code I am using is:

SqlConnection myConn = new
SqlConnection(ConfigurationSettings.AppSettings["strConnection"]);
SqlCommand myComm = new SqlCommand("Select SX_Image_Data from
SX_ACCSXDB_Images where chrBarCode = '" + Request.QueryString["invoice"] +
"'",myConn);

myConn.Open();
try
{
byte [] img = (byte[]) myComm.ExecuteScalar();
MemoryStream ms = new MemoryStream();
ms.Write(img, 0, img.Length);
Bitmap bmp = new Bitmap(ms);

bmp.Save(Response.OutputStream, ImageFormat.Tiff);

}
catch(Exception)
{
Response.Write("<center><h4>The Invoice you are requesting does not
exist in the system</h4></center>");
}


Nov 16 '05 #5

P: n/a
Maybe I should give more detail on what I want to do...

When I simply change the code I posted to ImageFormat.Gif.. it streams fine
to IE and opens.. life is good.

But since there are invoices with multiple pages, we would like to open as a
TIFF format in Windows Picture and Fax Viewer. (or default for TIFF on
client). Basically I need to stream this file to the client and then open in
this program (or default for TIFF). I initially thought that by streaming and
opening.. it is essentially placing a copy in the clients temp internet files
and then opening from there.

Thanks for all your help, keep the ideas rolling...

Nov 16 '05 #6

P: n/a
There is a free plugin that will allow you to view TIFF files in the
browser.
It can be downloaded from here:
http://www.alternatiff.com/

However, this will be needed to be installed at the client.
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Dennis Myrén" <de****@oslokb.no> wrote in message
news:xQ****************@news4.e.nsc.no...
Native TIFF support is not present in either Microsoft Internet Explorer
nor Mozilla FireFox.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Phil <Ph**@discussions.microsoft.com> wrote:
Hi I have an issue when trying to stream blob image data from a SQL
table to
a .aspx page. the code I have works for GIF and JPEG but the images can
be
multiple pages and we would like them to open in a TIFF format.

What comes back to the screen is garble.... Can anyone help? Thanks


I can't see anything there setting the content type - have you tried
that?

What happens if you save the output to disk and load it from explorer?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.