Reading Image Data from SQL Server To a Text File

G

Guest

Hello All:

I have a field in the database that is an Image. I have no idea how the
data is stored in here (Image, compressed, encrypted, plain text, etc). I am
trying to write the contents to a text file, image file, etc so I can see if
the data is stored in a way we can understand (we have been tasked to write
an app and the app needs to read this field, but we don't know what it really
contains).

How would I go about reading the data from this field and saving the
contents to a text field, as well as an image? I know conceptually how to do
it, but having issues with the syntax and actual code that is needed.

Thanks
Andy
 
N

Nicholas Paldino [.NET/C# MVP]

Andy,

If the image is compressed or encrypted, I don't know that looking at
the byte stream is going to do you much good.

Why not just save the contents to a file, and change the extension on
the file, see if anything works opening it?

Also, how is it that you can't know the storage format? Do you have
another system that accesses this DB? If so, do you have the code for that
system?
 
G

Guest

Nicholas:

Thank you for the response.

We are not sure if the image is compressed or encrypted. All that we know
at this time is the data is stored as an Image in the database. We have a
program that uses this data and displays the information. However: this is
a third party windows tool that we want to re-write portions (for reporting
purposes) for the web. So we are not sure how this software uses that image
data. As a result: we are not sure if the data is stored encrypted,
compressed, hashed or as plain text.

I am not really sure how to save this information to a text file, that is
the issue I am having at the moment. I can't find examples on how to do this
with values from a database.

Thanks
Andy

Nicholas Paldino said:
Andy,

If the image is compressed or encrypted, I don't know that looking at
the byte stream is going to do you much good.

Why not just save the contents to a file, and change the extension on
the file, see if anything works opening it?

Also, how is it that you can't know the storage format? Do you have
another system that accesses this DB? If so, do you have the code for that
system?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Andy said:
Hello All:

I have a field in the database that is an Image. I have no idea how the
data is stored in here (Image, compressed, encrypted, plain text, etc). I
am
trying to write the contents to a text file, image file, etc so I can see
if
the data is stored in a way we can understand (we have been tasked to
write
an app and the app needs to read this field, but we don't know what it
really
contains).

How would I go about reading the data from this field and saving the
contents to a text field, as well as an image? I know conceptually how to
do
it, but having issues with the syntax and actual code that is needed.

Thanks
Andy
 
N

Nicholas Paldino [.NET/C# MVP]

Andy,

If it is a byte array (which it would appear that it is), then just open
up a FileStream and then write the file out somewhere. You can change the
extension in explorer and see if any of the programs registered for those
extensions will open it up (like zip programs, image viewers, etc, etc).

If it is encrypted, then you are going to have a problem, since you
probably don't have access to the keys required for decryption.

Given the myriad number of possibilities, it is probably within your
best interests to contact the vendor and ask what the format is, try and get
it from them.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Andy said:
Nicholas:

Thank you for the response.

We are not sure if the image is compressed or encrypted. All that we know
at this time is the data is stored as an Image in the database. We have a
program that uses this data and displays the information. However: this
is
a third party windows tool that we want to re-write portions (for
reporting
purposes) for the web. So we are not sure how this software uses that
image
data. As a result: we are not sure if the data is stored encrypted,
compressed, hashed or as plain text.

I am not really sure how to save this information to a text file, that is
the issue I am having at the moment. I can't find examples on how to do
this
with values from a database.

Thanks
Andy

Nicholas Paldino said:
Andy,

If the image is compressed or encrypted, I don't know that looking at
the byte stream is going to do you much good.

Why not just save the contents to a file, and change the extension on
the file, see if anything works opening it?

Also, how is it that you can't know the storage format? Do you have
another system that accesses this DB? If so, do you have the code for
that
system?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Andy said:
Hello All:

I have a field in the database that is an Image. I have no idea how
the
data is stored in here (Image, compressed, encrypted, plain text, etc).
I
am
trying to write the contents to a text file, image file, etc so I can
see
if
the data is stored in a way we can understand (we have been tasked to
write
an app and the app needs to read this field, but we don't know what it
really
contains).

How would I go about reading the data from this field and saving the
contents to a text field, as well as an image? I know conceptually how
to
do
it, but having issues with the syntax and actual code that is needed.

Thanks
Andy
 
G

Guest

Nicholas:

Perhaps you might be so kind to show me what I am doing wrong (dr["scan"] is
the Image value from the database).

FileStream fs = new FileStream("C:\\test.txt", FileMode.Create);
BinaryWriter br = new BinaryWriter(fs);
br.Write(fs.Read(dr["scan"]));
br.Flush();
br.Close();
fs.Flush();
fs.Close();

Thanks
Andy

Nicholas Paldino said:
Andy,

If it is a byte array (which it would appear that it is), then just open
up a FileStream and then write the file out somewhere. You can change the
extension in explorer and see if any of the programs registered for those
extensions will open it up (like zip programs, image viewers, etc, etc).

If it is encrypted, then you are going to have a problem, since you
probably don't have access to the keys required for decryption.

Given the myriad number of possibilities, it is probably within your
best interests to contact the vendor and ask what the format is, try and get
it from them.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Andy said:
Nicholas:

Thank you for the response.

We are not sure if the image is compressed or encrypted. All that we know
at this time is the data is stored as an Image in the database. We have a
program that uses this data and displays the information. However: this
is
a third party windows tool that we want to re-write portions (for
reporting
purposes) for the web. So we are not sure how this software uses that
image
data. As a result: we are not sure if the data is stored encrypted,
compressed, hashed or as plain text.

I am not really sure how to save this information to a text file, that is
the issue I am having at the moment. I can't find examples on how to do
this
with values from a database.

Thanks
Andy

Nicholas Paldino said:
Andy,

If the image is compressed or encrypted, I don't know that looking at
the byte stream is going to do you much good.

Why not just save the contents to a file, and change the extension on
the file, see if anything works opening it?

Also, how is it that you can't know the storage format? Do you have
another system that accesses this DB? If so, do you have the code for
that
system?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hello All:

I have a field in the database that is an Image. I have no idea how
the
data is stored in here (Image, compressed, encrypted, plain text, etc).
I
am
trying to write the contents to a text file, image file, etc so I can
see
if
the data is stored in a way we can understand (we have been tasked to
write
an app and the app needs to read this field, but we don't know what it
really
contains).

How would I go about reading the data from this field and saving the
contents to a text field, as well as an image? I know conceptually how
to
do
it, but having issues with the syntax and actual code that is needed.

Thanks
Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top