We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Get filetype from stream


Is it possible to get the filetype out of a filestream in C# .NET?
I would like to make a ToPDFConverter(AStream) that can find out what kind of document (doc, docx, xls, ppt ) it’s going to convert via the AStream parameter. I’m thinking that its so much cooler than having to specify the filetype in the method call, ToPDFConverter(AStream, AFileType).
Any ideas?

Hello Sven,

Thanks for considering Aspose.

I'm afraid I'm not familiar with the approach to get FileType information from FileStream object, but you can get help from the following code which returns the FileType information for a particular file over the hard-drive. In order to get FileType information, you've to check the database of MIMEs - whether they're mapped from extensions or you need to check information in windows registry.


FileInfo fileInfo = new FileInfo(@"d:/pdftest/bugXLSnew22.xml");
string mimeType = "application/unknown";

RegistryKey regKey = Registry.ClassesRoot.OpenSubKey( fileInfo.Extension.ToLower());

if (regKey != null)
object contentType = regKey.GetValue("Content Type");
if (contentType != null)
mimeType = contentType.ToString();


In you still face any issue while accessing the information from FileStream Object, you can temporarily save the file over some location and use the above code to get FileType information.

In case it does not satisfy your requirements or you've any further query, please feel free to contact.