Link to home
Start Free TrialLog in
Avatar of u2kim
u2kim

asked on

Find File Format from VB6?

While user opening a file from the Commondialog Box,
How can differentiate the File name and the File Type (as .PDF or .DOC or .TXT etc)
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Try:

Extension = Right$(CommonDialog1.FileName,4)

cheers
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of itzme
itzme

This will put the value of the filetype into extension(1):

     Dim extension() As String

     extension = "." & Split(.FileTitle, ".", -1, vbTextCompare)

Hope thats what you want, to differentiate between all of them store this in an array of all the extensions.

The other thing you could be looking for could be filters, before the ".showOpen" (close,etc) in your code put in:

.Filter = "PostScript|*.pdf"&"|Word Document|*.doc"

and so on then put in the ".showOpen" bit. Hope one of these is what you want.
This will put the value of the filetype into extension(1):

     Dim extension() As String

     extension = "." & Split(.FileTitle, ".", -1, vbTextCompare)

Hope thats what you want, to differentiate between all of them store this in an array of all the extensions.

The other thing you could be looking for could be filters, before the ".showOpen" (close,etc) in your code put in:

.Filter = "PostScript|*.pdf"&"|Word Document|*.doc"

and so on then put in the ".showOpen" bit. Hope one of these is what you want.
What exactly do you want?
If you want to get the extension of the chosen file, look at ryancys' solution (or better itzme's: some extensions can have 4 characters and then ryancys' method fails).

But, as I understood, if you want to give the user the opportuntity to choose a file type, use (before the showopen or showsave):
CommonDialog1.Filter = "PDF-documents|*.pdf|Word-documents|*.doc|Text files|*.txt"
Avatar of u2kim

ASKER

I wont get the file name like Report1.DOC or Report1.PDF.
I will get the file name  as "Report1"  without any extension.
>>I will get the file name  as "Report1"  without any extension.
Tried the method i have posted and it should return the answer.
Are you talking about the filename displayed in the common dialog box or the filename returned from the "commondialog1.Filename" paramater, if its the one in the filelist displayed by the common dialog box its because you've turned of the "show all file types" in "folder options" in windows.
Hi u2kim,
This old question (QID 20566211) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

 -->Accept ryancys's comment as Answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER

GPrentice00
Cleanup Volunteer