|
-
Jun 5th, 2007, 09:27 AM
#1
Thread Starter
Fanatic Member
OLE Object
Hi All,
Is it possible to open a file that is stored in a Access database (OLE Object),
The file could be of any type?
Thanks
Loftty
-
Jun 5th, 2007, 11:39 PM
#2
Re: OLE Object
No. If it's stored in a database then it isn't strictly a file. It's a bunch of bytes, and you'll get those bytes from the database as a Byte array. If you wanted to open the content as a file in its native application you'd have to save it to disc first, which you could do quite easily. That's the sort of thing the Temp folder is for. That's exactly what a browser does when you choose to open a file directly from the Web: it downloads the bytes, saves a file in the Temp folder and then opens that. A well written application will ensure that the file is deleted afterwards, if at all possible.
-
Jun 6th, 2007, 07:06 AM
#3
Thread Starter
Fanatic Member
Re: OLE Object
Hi,
Could you give me an example of how to do this please?
Thanks
Loftty
-
Jun 6th, 2007, 09:54 AM
#4
Re: OLE Object
Hmmm... now I look at your first post again I could be wrong, given that your database contains OLE objects rather than actual file contents. When you retrieve a value from the database what is its type? Is it a Byte array?
-
Jun 7th, 2007, 04:44 AM
#5
Thread Starter
Fanatic Member
Re: OLE Object
Hi,
Yer it is a byte array
Thanks Lofty
-
Jun 8th, 2007, 04:22 AM
#6
Fanatic Member
Re: OLE Object
Hello,
Since I'll ask the same question, I think I'll join this conversation, if u don't mind loftty... ^_^
Suppose I save a picture file as an object field. How can I load the picture from that field ?
Thanks,
WJ
-
Jun 8th, 2007, 07:05 AM
#7
Thread Starter
Fanatic Member
Re: OLE Object
Hi Wen,
You can load the picture from a OLE field with something like this.
Code:
int PictureCol = 0;
string strConnFromDataBaseName = Provider + DataBaseName + ";User ID=" + Username + ";Password=" + Password + ";");
Connection cn = new OleDbConnection(strConnFromDataBaseName);
OleDbCommand cmd = new OleDbCommand("SELECT [Column Name] FROM [Table Name] " +
"WHERE [Condition]=30", cn);
cn.Open();
OleDbDataReader dr = cmd.ExecuteReader();
dr.Read();
Byte[] b = new Byte[(dr.GetBytes(PictureCol, 0, null, 0, int.MaxValue))];
dr.GetBytes(PictureCol, 0, b, 0, b.Length);
dr.Close();
cn.Close();
System.Drawing.ImageConverter cvrt = new ImageConverter();
Image img = (Image)cvrt.ConvertFrom(b);
//Do what you want with the image here
Loftty
-
Jun 10th, 2007, 09:57 PM
#8
Fanatic Member
Re: OLE Object
So, after putting the OLE object into "img" variable, I can use the var ?
~ WJ ~
-
Jun 11th, 2007, 03:32 AM
#9
Thread Starter
Fanatic Member
Re: OLE Object
Yes you can use img.
Loftty
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|