Sometimes it is necessary to detect the format of a document file before opening because the file extension does not guarantee that the file content is appropriate. For example, it is known that Crystal Reports often outputs documents in RTF format, but gives them the .doc extension. Therefore, if you are not sure what the actual content of the file is and want to avoid throwing an exception, you can use the DetectFileFormat method. This is a static (shared) method that accepts either a file name or stream object that contains the file data. The method returns a LoadFormat enumeration value that indicates the file type.
Example DetectFileFormat
Shows how to detect a document format.
[C#]
LoadFormat format = Document.DetectFileFormat(MyDir + "Document.doc");
Console.WriteLine("The document format is: " + format);
[Visual Basic]
Dim format As LoadFormat = Document.DetectFileFormat(MyDir & "Document.doc")
Console.WriteLine("The document format is: " & format)
[Java]
int loadFormat = Document.detectFileFormat(getMyDir() + "Document.doc");
System.out.println("The document format is: " + loadFormat);