473,386 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Stream blob data to a tiff format

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
6 2945
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Maurice Mertens | last post by:
Hello, I'm having troubles with saving a tiff-file with a certain compression and colordepth. This is the code I use: ----------------------------------------------------------------------...
3
by: hamvil79 | last post by:
I'm implementig a java web application using MySQL as database. The main function of the application is basically to redistribuite documents. Those documents (PDF, DOC with an average size around...
7
by: johnm | last post by:
We have a new CRM application that uses a DB2 7.2 database. Our users noted that the CRM application would not allow them to attach and store any documents over 2 meg in size. When asked, the...
11
by: Chris Fink | last post by:
I have setup an Oracle table which contains a blob field. How do I insert data into this field using C# and ADO.net?
5
by: Shane Story | last post by:
I can seem to get the dimensions of a frame in a multiframe tiff. After selecting activeframe, the Width/Height is still really much larger than the page's actual dimensions. When I split a...
9
by: matt | last post by:
hello, im doing my first ASP.NET app that inserts & retrieves files from Oracle (no need for a discussion on *that*!). i learned first-hand of the somewhat awkward technique for inserting...
0
by: bananularstyle | last post by:
Hi everyone, This is an issue I have been picking away at for the past two weeks and am running short of ideas. :-\ I am writing an ASP page that allows a user to open/save a tif image stored on...
8
by: =?Utf-8?B?Q2hyaXMgRmluaw==?= | last post by:
I am trying to make a minor modification to the code below and need some assistance. Currently this code is using the java.util, java.util.zip, and java.io assemblies from the vjslib.dll assembly....
1
by: David C | last post by:
Is there a way in ASP.Net 2.0 to stream individual TIFF image files into one TIFF file? If so, can you point me to any details? Thank you. David
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.