Free Support Forum -

Unable to determine file type from a stream. Please try to specify filename with extension explicitly


Hello, I was wondering if I could get some help with this error I am seeing.

We are using GroupDocs.Viewer for .NET version 16.10

My scenario is that I load a document from SharePoint and attempt to get the documentInfo from a stream of the document file bytes like so:

    ViewerHtmlHandler handler = new ViewerHtmlHandler(GetViewerConfig());

    using (MemoryStream ms = new MemoryStream(document.FileBytes))
        **var documentInfo = handler.GetDocumentInfo(ms);**

        int maxWidth = 0;
        int maxHeight = 0;

        foreach (var page in documentInfo.Pages)
            if (page.Height > maxHeight)
                maxHeight = page.Height;
                maxWidth = page.Width;

        docInfo = new DocInfo()
            DocumentGuid = documentInfo.Guid,
            DocumentName = document.FileName,
            PageCount = documentInfo.Pages.Count,
            PageNumber = 1,
            DocumentHeight = maxHeight,
            DocumentWidth = maxWidth

    return docInfo;

On the line marked in ** I get this exception
System.InvalidOperationException: ‘Unable to determine file type from a stream. Please try to specify filename with extension explicitly.’

Can anyone shed some light on this and provide some assistance?



Just to add, I also tried GroupDocs.Viewer version 18.11 and I see the same error.



Thanks for contacting support.

Would you please also share with us the problematic documents for which you are facing this issue? We shall be looking forward to your response.


This is one of the emails (.MSG) from SharePoint that I am unable to get document info for from the MemoryStream.


test (35.3 KB)



Thanks for sharing the problematic document with us.

We are able to reproduce your reported exception at our end. This issue has been logged into our internal Issue Tracking System as VIEWERNET-1832 for further investigation. We shall keep you notified in case of any updates.



We have got the updates regarding your reported issue.

Although GroupDocs.Viewer tries to detect the file type of the input stream, in some cases the file type can’t be detected and the API throws the exception. Furthermore, the file type detection feature does not guarantee that file type would be detected correctly. So in your case, we recommend you to please use the method which accepts file name with extension as the second parameter:

var documentInfo = handler.GetDocumentInfo(ms, Guid.NewGuid() + ".msg");

(NOTE: Guid.NewGuid() is added to make sure that the API will create a separate directory in cache folder for each file.)

For reference, please download this (56.0 KB) sample application. Hope it helps.



The issue you have faced earlier (logged as VIEWERNET-1832) has been fixed in this release.