Hi Derek,
Thanks for your inquiry. Yes, you can detect the file format of MS Word documents by using Aspose.Words. Please use the following code snippet to detect the file format of MS Word documents.
// Load the document without a file extension into a stream and use the DetectFileFormat method to detect it's format.
FileStream docStream = File.OpenRead(MyDir + @"Document.FileWithoutExtension");
// The file format of this document is actually ".doc"
FileFormatInfo info = FileFormatUtil.DetectFileFormat(docStream);
Console.WriteLine("The document format is: " + FileFormatUtil.LoadFormatToExtension(info.LoadFormat));
Console.WriteLine("Document is encrypted: " + info.IsEncrypted);
Console.WriteLine("Document has a digital signature: " + info.HasDigitalSignature);
With FileFormatInfo, you can detect only file formats listed in the following link: http://www.aspose.com/docs/display/wordsnet/LoadFormat+Enumeration
Please read the following documentation links for your reference:
- http://www.aspose.com/docs/display/wordsnet/How+to++Detect+the+File+Format
- http://www.aspose.com/docs/display/wordsnet/FileFormatUtil+Class
- https://reference.aspose.com/words/net/aspose.words/fileformatinfo/
I am moving this thread to the Aspose.Total forum. My colleagues from the Aspose.PDF, Aspose.Slides, and Aspose.Cells teams will reply to you shortly about the detection of file formats (pdf, xls(x), ppt(x)).
Hi Derek,
PresentationEx pres = new PresentationEx(PresentationStream);SourceFormatEx format = pres.SourceFormat;
Many thanks it would be useful for a product like Aspose.Total to include a single mechanism to detect all file types from a stream. This would also be a differentiator driving decisions to purchase the total product rather than individual products. Can you put this on a “would like to have” list?
Hi Derek,
Thanks for contacting support.
I am a representative from the Aspose.Pdf team. The simplest way to determine if the source file in a stream is a PDF is to try initializing an Aspose.Pdf.Document object in a Try-Catch block, and if you do not encounter any exception while reading the source file, the input document is in PDF format. Please take a look at the following code snippet.
[C#]
FileStream inputfile = new FileStream(@"C:\pdftest\New Microsoft PowerPoint Presentation.pptx", FileMode.Open);
try
{
Document doc = new Document(inputfile);
Console.WriteLine("Input document is proper PDF");
}
catch (Aspose.Pdf.Exceptions.InvalidPdfFileFormatException ex)
{
Console.WriteLine("Source file is not PDF. " + ex.Message);
}
inputfile.Close();
Besides this, you may consider determining the MIME type of the file. You may refer to the discussion over this link.
dl129302:
Many thanks it would be useful for a product like Aspose.Total to include a single mechanism to detect all file types from a stream. This would also be a differentiator driving decisions to purchase the total product rather than individual products. Can you put this on a "would like to have" list?
The mime type for an excel document is being returned as application/octet-stream. It is correctly recognised by Aspose.Cells. I cannot rely on the mimetype being correct even though the documents were created by the application provider using Aspose.
The mime type for an excel document is being returned as application/octet-stream. It is correctly recognised by Aspose.Words. I cannot rely on the mimetype being correct even though the documents were created by the application provider using Aspose.
PresentationEx is not a type in the Aspose.Slides version I am working with.
Hi,