Preview Attachment 'HTML' file in Form

jay_x

New member
Joined
Nov 9, 2012
Messages
3
Programming Experience
Beginner
Hi All,

I'm building an Access database of HTML files. I'm using the 'Attachment' feature of Access to import the HTML files.

I want to preview the HTML code (not the website) on the form itself. Any assistance is greatly appreciated.

I've programmed in the past but it's been awhile.

thanks!!
j-
 
This is actually not straightforward. There's no specific way to work with the attachment data type using ADO.NET and the ACE OLE DB provider. I did see a bit of a hack not that long ago that seems work but is yet to be proven to work in all cases. It involved treating an Attachment value as a Byte array, which is what I would expect, but then removing the first N Bytes from it, which seems to be a header that gets added somewhere. I don't recall what that number N is and I don't recall where I saw the information. It shouldn't be too hard to work out though, so I'll do a bit of testing and get back to you. Watch this space!
 
Hmmm... I've been doing a bit more research and it's even less straightforward than I thought. The attachment column is retrieved by ADO.NET with a data type of String and it contains simply a list of file names. To get at the binary data of the attachment requires more work. I believe that you can get at the data more easily using DAO, but it would be nice to be able to avoid that. I'll look a bit deeper and see if I can find the information I mentioned earlier.
 
Four posts ago in this forum: http://www.vbdotnetforums.com/ms-access/53588-problem-attachment-feild.html there was a link to discussion about that.
The variable in those bytes is the unicode value of the file extension/format (example 6A 00 70 00 67 00 = jpg)

So I've discovered in my messing about. I'm just finished a demo that will retrieve and display attachments from an ACCDB database so I'll provide a link when it's uploaded. I'll be looking to enhance that a bit and allow saving of attachments, but I haven't tested that yet.
 
thanks for all your efforts!

Part 2 of this question is then how difficult would it be to manipulate the html code. For instance, what I really want to do is extract certain html code based on tags then dump those onto another access table.

For example I want to search the html file for a tag called <mytag> all the way to </mytag> then copy all the text in between (including the tags) and dump that text onto a table.

If this sounds way too cumbersome, then I may just use a different approach.

thanks!!
j-
 
You could just treat the HTML code as text as use a Regex. I'm no expert with regular expressions and I've never used one to extract data from HTML but, if you search online, I'm sure you'll find various examples of doing so.

The other option would be to use the HTML Agility Pack, which is a .NET library that provides a DOM for accessing HTML code, something like an XmlDocument. Again, I've never used it but I'm sure that you can find examples online. In fact, the download page provides a link to some code examples.

By the way, you can use the Encoding.GetString method to convert the Byte array you get using the method I demonstrated into a String containing the HTML code of your document.
 
Ok, will certainly give that a try. Thanks again!!

j-



You could just treat the HTML code as text as use a Regex. I'm no expert with regular expressions and I've never used one to extract data from HTML but, if you search online, I'm sure you'll find various examples of doing so.

The other option would be to use the HTML Agility Pack, which is a .NET library that provides a DOM for accessing HTML code, something like an XmlDocument. Again, I've never used it but I'm sure that you can find examples online. In fact, the download page provides a link to some code examples.

By the way, you can use the Encoding.GetString method to convert the Byte array you get using the method I demonstrated into a String containing the HTML code of your document.
 
Back
Top