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

ole

P: n/a
how properly insert and render image from ole object in access database with
asp.net/c#?

i always get only "red x" :(

tnx alot




----------
storing
---------
string filename = Path.GetFileName(picture.PostedFile.FileName);
int filesize = picture.PostedFile.ContentLength;
string filetype = picture.PostedFile.ContentType;
byte[] filedata = new byte[filesize];

picture.PostedFile.InputStream.Read(filedata, 0, filesize);

System.Data.OleDb.OleDbConnection conn = new
System.Data.OleDb.OleDbConnection("Provider=Micros oft.Jet.OLEDB.4.0;Data
Source=" + Server.MapPath("../databases/base.mdb"))
System.Data.OleDb.OleDbCommand comm = new
System.Data.OleDb.OleDbCommand();

conn.Open();
comm.CommandText = "INSERT INTO files
(filename,filesize,filetype,filedata) VALUES
('"+filename+"',"+filesize+",'"+filetype+"','"+fil edata+"')";
comm.Connection = conn;
comm.ExecuteNonQuery();
conn.Close();
---------------------------------------------------------------



---------------------------------------------------------------
rendering
---------------------------------------------------------------
string base_loc =
System.Configuration.ConfigurationSettings.AppSett ings["base_loc"];
System.Data.OleDb.OleDbConnection conn = new
System.Data.OleDb.OleDbConnection("Provider=Micros oft.Jet.OLEDB.4.0;Data
Source=" + Server.MapPath(""+base_loc+""));
System.Data.OleDb.OleDbCommand comm = new System.Data.OleDb.OleDbCommand();

string filename;
string filetype;
int filesize;
byte[] filedata;

conn.Open();
comm.CommandText = "SELECT filename,filesize,filetype,filedata FROM files";
comm.Connection = conn;

System.Data.OleDb.OleDbDataReader reader = comm.ExecuteReader();

reader.Read();

filename = reader.GetString(0);
filesize = reader.GetInt16(1);
filetype = reader.GetString(2);
filedata = new Byte[filesize];
reader.GetBytes(3, 0, filedata, 0, filesize);

Page.Response.Clear();
Page.Response.AddHeader("Content-Disposition", "attachment;
filename=DisplayImage.jpg;");
Page.Response.AddHeader("Content-Lenght", filesize.ToString());
Page.Response.ContentType = filetype;
Page.Response.BinaryWrite(filedata);
Page.Response.Flush();

reader.Close();
conn.Close();
Feb 1 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.