Open different file types

Katipo

New member
Joined
Dec 25, 2005
Messages
4
Programming Experience
1-3
Hi All,

I am currently working on a document manager type application in vb 2008.

I want to be able to open and preview different file types in the app in addition to being able to open them with their associated programs.

Is it possible to create a universal file opener that will open and display any file type (and if so how do I do it) or do I have to write a separate file opener for each different file type I wish to support?

Thanks
 
A "universal file opener"...no

You can create one that opens the most common types of files, but you can't create one that opens a file type that, as of this moment, doesn't exist.
 
All files contain a series of bytes. What exactly those bytes mean depend on the file format. In text files the bytes represent characters. In Bitmap files they represent pixel colours. They can mean anything that the file format's author wants them to mean.

In order to display a file as it was intended to be seen, you need to understand the file format so that you can read the binary data, interpret it and then convert it to the correct visual form. How many file formats do you understand that well?

Certain file formats can be handled for you by the Framework. For instance, TXT and RTF files can be read and displayed in a TextBox or RichTextBox. JPG and BMP files can be turned into an Image object and displayed in a PictureBox. That's about as far as it goes though: text and images. If you want to display Microsoft Office documents then you could use a WebBrowser control and let the installed applications handle files for you and the same goes for PDFs and Adobe Reader. That won't work if Micorsoft Office and Adobe Reader, or some alternative that also provide ActiveX controls are installed.

Basically you're going to have to pick each file type that you want to support and then write the appropriate code to open and display files of that type in the appropriate manner. You'll have to handle them on a case by case basis and some may require thrid-party components. Using a WebBrowser may be the most flexible as it can probably render text and images directly too, as well as embedding ActiveX controls for Office documents and the like.
 
Back
Top