retrieve image datatype and store it as a file

K

kabin selvam

Hi,

my scenario is like this, I have my document (word.or
excel or pdf) stored a s a binary value(image datatype) in
database, I need it to convert back into thedocument and
save it as the file in my local system,

Is there any way of retrieving the image datatype and
store it as a file in our local system in c#

regards,
Kabin
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi,

I'd introduce an additional column in the data table describing the type of
the binary data stored.
The values in this column would most likely serve as foreign keys into a
dedicated dictionary containing all possible image types.
 
K

kabin selvam

Hi,

I do have a column named mime type which has the types like
html/word,text/plain etc.

my code is like this

string connstr="server=knowsys-server2;database=Argos;uid=sa";
string sql="SELECT AttachFilename,Attachment, MimeType FROM
EmailAttachments WHERE AttachmentID = 7";
SqlConnection connection = new SqlConnection(connstr);
SqlCommand command = new SqlCommand(sql, connection);
connection.Open();
SqlDataReader dr = command.ExecuteReader();
System.Byte[] bytPassword = null;
string imgPassward = "";

while(dr.Read())
{
bytPassword =
(System.Byte[])dr.GetValue(dr.GetOrdinal(("Attachment")));
}

dr.Close();

imgPassward =
Encoding.ASCII.GetString(bytPassword).ToString().Trim();
//string imgPasswa = Convert.ToBase64String(bytPassword);
//imgPasswar = (Encoding.UTF8.GetDecoder());
Response.Write("atlast the string value is " + imgPassward);


but this works for only html\text types , for other types it returns me
an error.

it would be much helpfull if you could help me to solve this retrieving
problem

thanks,
kabin.
 

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