If I have byte[] parameter, is there any way to know if it is a Word or Pdf or Excel file different of doing this?
Hi Mauricio,
Thanks for your inquiry. Sure, in case of a Word document, the following code snippet shows how to use the FileFormatUtil methods to detect the format of a document:
FileStream docStream = File.OpenRead(@"C:\Temp\somedocument");
FileFormatInfo info = FileFormatUtil.DetectFileFormat(docStream);
LoadFormatloadFormat = info.LoadFormat;
stringfileExtension = FileFormatUtil.LoadFormatToExtension(loadFormat);
I hope, this helps.
Moreover, as your query involves multiple file formats, I am moving your thread in Aspose.Total forum where you’ll be guided appropriately.
Best regards,
Hi,
Thanks for your posting and using Aspose.
In case of Aspose.Cells, you can detect the file formats of different Excel documents before actually loading them using the CellsHelper.DetectFileFormat.
Please see the following documentation article for your reference.
http://www.aspose.com/docs/display/cellsnet/How+to+Detect+the+File+Format
mega15:
If I have byte[] parameter, is there any way to know if it is a Word or Pdf or Excel file different of doing this?try{pdfDocument = new Pdf.Document(documentStream);} catch (Exception) {isPdf = false;}
// instantiate PdfFileInfo object<o:p></o:p>
PdfFileInfo info = new PdfFileInfo();
// bind the source file
info.BindPdf("c:/pdftest/Example.jpg");
// display either the file is PDF for not
Console.WriteLine("Is
Pdf file - "+ info.IsPdfFile);