473,624 Members | 2,253 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I determine filetype/extension of files stored in OLE fields?

I have an application that allows embedded storage of ANY chosen file
in an OLE field. The file could have been dragged-and-dropped into
the field or it might have been selected and imported programmaticall y
using the common file dialog. Regardless, I need to determine the
filetype/extension of each of these files already stored in my OLE
fields and display it for the user.

Double-clicking the raw OLE field or using the
.Verb = acOLEVerbOpen
.Action = acOLEActivate
methods will launch whatever application is associated with the type
of file stored in the OLE field, so, somehow, that information (.XLS,
..DOC, .MPG, .PDF, etc.) must be available -- but where? I want to be
able to list, in a form, my records that contain the OLE fields along
with other info describing the OLE contents, such as size (obtainable
via the FileSize function). Is there a way for me to get at the file
extension as well?

Thanks for any help you can offer!
Nov 12 '05 #1
18 7706
TC
The fact that it can launch the appropriate application, does not
necessarily mean that it knows the name of the original file. It might just
be storing a so-called ProgID, eg. "Excel.Applicat ion". That is enough to
identify the relevant application. If the object is embedded - not linked -
I doubt that the name of the original file is stored, at all.

HTH,
TC
"Keith Brown" <ks*****@one.ne t> wrote in message
news:3c******** *************** ***@posting.goo gle.com...
I have an application that allows embedded storage of ANY chosen file
in an OLE field. The file could have been dragged-and-dropped into
the field or it might have been selected and imported programmaticall y
using the common file dialog. Regardless, I need to determine the
filetype/extension of each of these files already stored in my OLE
fields and display it for the user.

Double-clicking the raw OLE field or using the
.Verb = acOLEVerbOpen
.Action = acOLEActivate
methods will launch whatever application is associated with the type
of file stored in the OLE field, so, somehow, that information (.XLS,
.DOC, .MPG, .PDF, etc.) must be available -- but where? I want to be
able to list, in a form, my records that contain the OLE fields along
with other info describing the OLE contents, such as size (obtainable
via the FileSize function). Is there a way for me to get at the file
extension as well?

Thanks for any help you can offer!

Nov 12 '05 #2
"TC" <a@b.c.d> wrote in message news:<106731317 0.971034@teutho s>...
The fact that it can launch the appropriate application, does not
necessarily mean that it knows the name of the original file. It might just
be storing a so-called ProgID, eg. "Excel.Applicat ion". That is enough to
identify the relevant application. If the object is embedded - not linked -
I doubt that the name of the original file is stored, at all.


Right. I figured the full filename was no longer available and really
have no need for it. The ProgID you refer to might even be better
than an extension, since it spells out the actual name of the
associated application. I would be pretty happy if someone could show
me some code that could produce either one! Thanks for your response.
Nov 12 '05 #3
If you look at what's actually in the field you'll find that it contains the
filename and the full (short) path to the file.

So a nasty first stab at code to get this info could look like this

Function PathFromOLEFiel d()
Dim loDb As DAO.Database
Dim loRst As DAO.Recordset
Dim loFld As DAO.Field
Dim varChunk As Variant
Dim lngCount As Long
Dim strRet As String
Dim strFile As String
Dim strPath As String
Dim intInstr As Integer

Set loDb = Access.CurrentD b
Set loRst = loDb.OpenRecord set("Table1")
Set loFld = loRst.Fields("H mmm")
Do Until loRst.EOF
varChunk = loFld.GetChunk( 70, 500)
strRet = ""
For lngCount = LBound(varChunk ) To UBound(varChunk )
strRet = strRet & Chr(varChunk(ln gCount))
Next
intInstr = InStr(strRet, Chr(0))
strFile = Left(strRet, intInstr - 1)
strRet = Mid(strRet, intInstr + 1)
intInstr = InStr(strRet, Chr(0) & Chr(0))
strPath = Left(strRet, intInstr - 1)
Debug.Print strFile
Debug.Print strPath
loRst.MoveNext
Loop
Set loFld = Nothing
loRst.Close
Set loRst = Nothing
Set loDb = Nothing
End Function

Terry

"Keith Brown" <ks*****@one.ne t> wrote in message
news:3c******** *************** ***@posting.goo gle.com...
"TC" <a@b.c.d> wrote in message news:<106731317 0.971034@teutho s>...
The fact that it can launch the appropriate application, does not
necessarily mean that it knows the name of the original file. It might just be storing a so-called ProgID, eg. "Excel.Applicat ion". That is enough to identify the relevant application. If the object is embedded - not linked - I doubt that the name of the original file is stored, at all.


Right. I figured the full filename was no longer available and really
have no need for it. The ProgID you refer to might even be better
than an extension, since it spells out the actual name of the
associated application. I would be pretty happy if someone could show
me some code that could produce either one! Thanks for your response.

Nov 12 '05 #4
Terry,

Thanks so much for posting the code. I tried it out and,
unfortunately, was not able to get anything intelligible as output.
(The filename value [strFile] for each field was displaying as ".8"
and the pathname was empty.) Is it possible your code is what one
would use to display the contents of an OLE field containing a link to
a file, rather than a complete embedded file? All of my OLE fields
contain embedded files ONLY.

Keith
Nov 12 '05 #5
TC
Where do the 70 & 500 come from? (getchunk 70,500)

TC
"Terry Kreft" <te*********@mp s.co.uk> wrote in message
news:bn******** **@newsreaderg1 .core.theplanet .net...
If you look at what's actually in the field you'll find that it contains the filename and the full (short) path to the file.

So a nasty first stab at code to get this info could look like this

Function PathFromOLEFiel d()
Dim loDb As DAO.Database
Dim loRst As DAO.Recordset
Dim loFld As DAO.Field
Dim varChunk As Variant
Dim lngCount As Long
Dim strRet As String
Dim strFile As String
Dim strPath As String
Dim intInstr As Integer

Set loDb = Access.CurrentD b
Set loRst = loDb.OpenRecord set("Table1")
Set loFld = loRst.Fields("H mmm")
Do Until loRst.EOF
varChunk = loFld.GetChunk( 70, 500)
strRet = ""
For lngCount = LBound(varChunk ) To UBound(varChunk )
strRet = strRet & Chr(varChunk(ln gCount))
Next
intInstr = InStr(strRet, Chr(0))
strFile = Left(strRet, intInstr - 1)
strRet = Mid(strRet, intInstr + 1)
intInstr = InStr(strRet, Chr(0) & Chr(0))
strPath = Left(strRet, intInstr - 1)
Debug.Print strFile
Debug.Print strPath
loRst.MoveNext
Loop
Set loFld = Nothing
loRst.Close
Set loRst = Nothing
Set loDb = Nothing
End Function

Terry

"Keith Brown" <ks*****@one.ne t> wrote in message
news:3c******** *************** ***@posting.goo gle.com...
"TC" <a@b.c.d> wrote in message news:<106731317 0.971034@teutho s>...
The fact that it can launch the appropriate application, does not
necessarily mean that it knows the name of the original file. It might just be storing a so-called ProgID, eg. "Excel.Applicat ion". That is enough to identify the relevant application. If the object is embedded - not linked - I doubt that the name of the original file is stored, at all.


Right. I figured the full filename was no longer available and really
have no need for it. The ProgID you refer to might even be better
than an extension, since it spells out the actual name of the
associated application. I would be pretty happy if someone could show
me some code that could produce either one! Thanks for your response.


Nov 12 '05 #6

No I wrote it using embedded files.

I did a test on it with 3 different file types (*..txt, *.zip and *.mdb) and
it works for each of these.

What file type are you embedding?

Terry

"Keith Brown" <ks*****@one.ne t> wrote in message
news:3c******** *************** ***@posting.goo gle.com...
Terry,

Thanks so much for posting the code. I tried it out and,
unfortunately, was not able to get anything intelligible as output.
(The filename value [strFile] for each field was displaying as ".8"
and the pathname was empty.) Is it possible your code is what one
would use to display the contents of an OLE field containing a link to
a file, rather than a complete embedded file? All of my OLE fields
contain embedded files ONLY.

Keith

Nov 12 '05 #7
Empiricism.

By grabbing a number of different records I observed that:-
1) the filename consistently appeared at byte 70
2) the filename was terminated with a single Null character (Chr(0))
3) the filename was followed by the full path terminated by a pair of
Null characters.
4) the path was in short form and therefore the length of the path plus
file path are
unlikely to exceed 500 bytes (520 (2 * MAX_PATH ) would have been a
better bet)

but as I say it's dirty code. Which means it shows a principle.

Terry
"TC" <a@b.c.d> wrote in message news:1067394655 .92126@teuthos. ..
Where do the 70 & 500 come from? (getchunk 70,500)

TC
"Terry Kreft" <te*********@mp s.co.uk> wrote in message
news:bn******** **@newsreaderg1 .core.theplanet .net...
If you look at what's actually in the field you'll find that it contains

the
filename and the full (short) path to the file.

So a nasty first stab at code to get this info could look like this

Function PathFromOLEFiel d()
Dim loDb As DAO.Database
Dim loRst As DAO.Recordset
Dim loFld As DAO.Field
Dim varChunk As Variant
Dim lngCount As Long
Dim strRet As String
Dim strFile As String
Dim strPath As String
Dim intInstr As Integer

Set loDb = Access.CurrentD b
Set loRst = loDb.OpenRecord set("Table1")
Set loFld = loRst.Fields("H mmm")
Do Until loRst.EOF
varChunk = loFld.GetChunk( 70, 500)
strRet = ""
For lngCount = LBound(varChunk ) To UBound(varChunk )
strRet = strRet & Chr(varChunk(ln gCount))
Next
intInstr = InStr(strRet, Chr(0))
strFile = Left(strRet, intInstr - 1)
strRet = Mid(strRet, intInstr + 1)
intInstr = InStr(strRet, Chr(0) & Chr(0))
strPath = Left(strRet, intInstr - 1)
Debug.Print strFile
Debug.Print strPath
loRst.MoveNext
Loop
Set loFld = Nothing
loRst.Close
Set loRst = Nothing
Set loDb = Nothing
End Function

Terry

"Keith Brown" <ks*****@one.ne t> wrote in message
news:3c******** *************** ***@posting.goo gle.com...
"TC" <a@b.c.d> wrote in message news:<106731317 0.971034@teutho s>...
> The fact that it can launch the appropriate application, does not
> necessarily mean that it knows the name of the original file. It
might just
> be storing a so-called ProgID, eg. "Excel.Applicat ion". That is
enough to
> identify the relevant application. If the object is embedded - not

linked -
> I doubt that the name of the original file is stored, at all.

Right. I figured the full filename was no longer available and really
have no need for it. The ProgID you refer to might even be better
than an extension, since it spells out the actual name of the
associated application. I would be pretty happy if someone could show
me some code that could produce either one! Thanks for your response.



Nov 12 '05 #8
TC

"Terry Kreft" <te*********@mp s.co.uk> wrote in message
news:bn******** **@newsreaderm1 .core.theplanet .net...
Empiricism.

By grabbing a number of different records I observed that:-
1) the filename consistently appeared at byte 70
2) the filename was terminated with a single Null character (Chr(0))
3) the filename was followed by the full path terminated by a pair of
Null characters.
4) the path was in short form and therefore the length of the path plus
file path are
unlikely to exceed 500 bytes (520 (2 * MAX_PATH ) would have been a
better bet)

but as I say it's dirty code. Which means it shows a principle.
Maybe! But there is tons of dirty space inside many MS file structures. So
the appearance of particular data, at a particular place, on a few
occasions, could easily arise from random causes.

TC


Terry
"TC" <a@b.c.d> wrote in message news:1067394655 .92126@teuthos. ..
Where do the 70 & 500 come from? (getchunk 70,500)

TC
"Terry Kreft" <te*********@mp s.co.uk> wrote in message
news:bn******** **@newsreaderg1 .core.theplanet .net...
If you look at what's actually in the field you'll find that it contains
the
filename and the full (short) path to the file.

So a nasty first stab at code to get this info could look like this

Function PathFromOLEFiel d()
Dim loDb As DAO.Database
Dim loRst As DAO.Recordset
Dim loFld As DAO.Field
Dim varChunk As Variant
Dim lngCount As Long
Dim strRet As String
Dim strFile As String
Dim strPath As String
Dim intInstr As Integer

Set loDb = Access.CurrentD b
Set loRst = loDb.OpenRecord set("Table1")
Set loFld = loRst.Fields("H mmm")
Do Until loRst.EOF
varChunk = loFld.GetChunk( 70, 500)
strRet = ""
For lngCount = LBound(varChunk ) To UBound(varChunk )
strRet = strRet & Chr(varChunk(ln gCount))
Next
intInstr = InStr(strRet, Chr(0))
strFile = Left(strRet, intInstr - 1)
strRet = Mid(strRet, intInstr + 1)
intInstr = InStr(strRet, Chr(0) & Chr(0))
strPath = Left(strRet, intInstr - 1)
Debug.Print strFile
Debug.Print strPath
loRst.MoveNext
Loop
Set loFld = Nothing
loRst.Close
Set loRst = Nothing
Set loDb = Nothing
End Function

Terry

"Keith Brown" <ks*****@one.ne t> wrote in message
news:3c******** *************** ***@posting.goo gle.com...
> "TC" <a@b.c.d> wrote in message news:<106731317 0.971034@teutho s>...
> > The fact that it can launch the appropriate application, does not
> > necessarily mean that it knows the name of the original file. It might just
> > be storing a so-called ProgID, eg. "Excel.Applicat ion". That is enough to
> > identify the relevant application. If the object is embedded - not
linked -
> > I doubt that the name of the original file is stored, at all.
>
> Right. I figured the full filename was no longer available and

really > have no need for it. The ProgID you refer to might even be better
> than an extension, since it spells out the actual name of the
> associated application. I would be pretty happy if someone could show > me some code that could produce either one! Thanks for your response.



Nov 12 '05 #9
If you're trying to start an argument then go ahead, you're only arguing
with yourself.

I refer you back to my original posting.

Take note of the phrase "... a nasty first stab at code ..." .

This was meant to imply that
1) the code cited was not tested to any great degree but that it did
work on the tests carried out.
2) it would need work on it to polish and improve it , even to possibly
disprove it as a method.

Of course if you are in the know on how an OLE Object field in Access stores
the object and the relevant references to it then go ahead and enlighten us,
otherwise we're stuck with the empirical approach.
Terry

"TC" <a@b.c.d> wrote in message news:1067475808 .597311@teuthos ...

"Terry Kreft" <te*********@mp s.co.uk> wrote in message
news:bn******** **@newsreaderm1 .core.theplanet .net...
Empiricism.

By grabbing a number of different records I observed that:-
1) the filename consistently appeared at byte 70
2) the filename was terminated with a single Null character (Chr(0))
3) the filename was followed by the full path terminated by a pair of
Null characters.
4) the path was in short form and therefore the length of the path plus
file path are
unlikely to exceed 500 bytes (520 (2 * MAX_PATH ) would have been a better bet)

but as I say it's dirty code. Which means it shows a principle.


Maybe! But there is tons of dirty space inside many MS file structures. So
the appearance of particular data, at a particular place, on a few
occasions, could easily arise from random causes.

TC


Terry
"TC" <a@b.c.d> wrote in message news:1067394655 .92126@teuthos. ..
Where do the 70 & 500 come from? (getchunk 70,500)

TC
"Terry Kreft" <te*********@mp s.co.uk> wrote in message
news:bn******** **@newsreaderg1 .core.theplanet .net...
> If you look at what's actually in the field you'll find that it

contains the
> filename and the full (short) path to the file.
>
> So a nasty first stab at code to get this info could look like this
>
> Function PathFromOLEFiel d()
> Dim loDb As DAO.Database
> Dim loRst As DAO.Recordset
> Dim loFld As DAO.Field
> Dim varChunk As Variant
> Dim lngCount As Long
> Dim strRet As String
> Dim strFile As String
> Dim strPath As String
> Dim intInstr As Integer
>
> Set loDb = Access.CurrentD b
> Set loRst = loDb.OpenRecord set("Table1")
> Set loFld = loRst.Fields("H mmm")
> Do Until loRst.EOF
> varChunk = loFld.GetChunk( 70, 500)
> strRet = ""
> For lngCount = LBound(varChunk ) To UBound(varChunk )
> strRet = strRet & Chr(varChunk(ln gCount))
> Next
> intInstr = InStr(strRet, Chr(0))
> strFile = Left(strRet, intInstr - 1)
> strRet = Mid(strRet, intInstr + 1)
> intInstr = InStr(strRet, Chr(0) & Chr(0))
> strPath = Left(strRet, intInstr - 1)
> Debug.Print strFile
> Debug.Print strPath
> loRst.MoveNext
> Loop
> Set loFld = Nothing
> loRst.Close
> Set loRst = Nothing
> Set loDb = Nothing
> End Function
>
>
>
> Terry
>
> "Keith Brown" <ks*****@one.ne t> wrote in message
> news:3c******** *************** ***@posting.goo gle.com...
> > "TC" <a@b.c.d> wrote in message news:<106731317 0.971034@teutho s>... > > > The fact that it can launch the appropriate application, does not > > > necessarily mean that it knows the name of the original file. It

might
> just
> > > be storing a so-called ProgID, eg. "Excel.Applicat ion". That is

enough
> to
> > > identify the relevant application. If the object is embedded - not > linked -
> > > I doubt that the name of the original file is stored, at all.
> >
> > Right. I figured the full filename was no longer available and really > > have no need for it. The ProgID you refer to might even be better
> > than an extension, since it spells out the actual name of the
> > associated application. I would be pretty happy if someone could show > > me some code that could produce either one! Thanks for your response. >
>



Nov 12 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
39342
by: Sami Viitanen | last post by:
Hello, How can I check if a file is binary or text? There was some easy way but I forgot it.. Thanks in adv.
6
6649
by: J. Shrimp, Jr. | last post by:
Following code exports tables as text files: For Each tdf In db.TableDefs StrTblName = tdf.Name Me.txtProgName = StrTblName Me.txtProgName.Requery tblAtt = tdf.Attributes moddate = tdf.LastUpdated If Left(StrTblName, 3) <> "tbl" And tblAtt = 0 Then strSQL = "INSERT INTO tmpExport ( Code ) SELECT _
6
14320
by: Kaki | last post by:
Given a file, how do I know if it's ascii or unicode or binary? And how do I know if it's rtf or html or etc? In other words, how do I find the stream type or mime type? (No, file extension cannot be the answer) Thanks *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
4
1408
by: Paul | last post by:
Hi! I want my web application to be able to handle files with the extension ..mspx (my own extension). The new extension should be handled exatly the way aspx files are handled, but with some additional code specific to the .mspx extension files. I thought this would be an easy task, but maby I've cornored myself into a wrong path. I've set the mapping correct in IIS, so that asp.net manages the new extension. I've also created a...
7
2911
by: Adam | last post by:
Im trying to add an httphandler for all *.sgf file extensions. I have developed the handler, 1. installed it into the gac 2. added it to the machine.config: <httpHandlers> <add verb="*" path="*.sgf" type="CustomExtensionHandler, Extenders.CustomExtensionHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d831d925597c1031" validate="True"/> </httpHandlers>
7
8346
by: kids_pro | last post by:
I found FileInfo expose alot of methods & properties. However I can't get FileType from FileInfo I can only get File extension. How can I get fileType any build-in library allow me to do that? If not please advice on what is the best way to get file type. Many thanks, kids
40
2960
by: Jeff | last post by:
I have a system on a network and want to determine if anyone is currently connected to the back-end files. An interesting twist is that I have noticed that some users can be connected (have the front end open at the first form) and even though this links to the back-end files, there are no ldb files created. This is so I know when it is safe to compact the back-end files without going round to make sure everyone is logged off. User...
3
9109
by: Phoe6 | last post by:
Hi all, I had a filesystem crash and when I retrieved the data back the files had random names without extension. I decided to write a script to determine the file extension and create a newfile with extension. --- method 1: # File extension utility. import os
38
5057
by: ted | last post by:
I have an old link that was widely distributed. I would now like to put a link on that old page that will go to a new page without displaying anything.
0
8238
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8174
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8680
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8624
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8336
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6111
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4082
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1786
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.