Free Support Forum - aspose.com

Detecting if Aspose.Slides can handle a stream (C# . NET)

Hi there,

We are currently trying to outline a strategy for detecting the Aspose component (starting from Detect file types from stream) that could handle a stream based on utilities function like:

                var fileFormatInfo = Aspose.Cells.FileFormatUtil.DetectFileFormat(input);
                if (fileFormatInfo.LoadFormat != Aspose.Cells.LoadFormat.Unknown)
                {
                    canHandle = true;
                }

Aspose.Slides.NET 20.2.0 does not have such utilities functions and we currently use this piece of code:

                    var canHandle = false;
                    try
                    {
                        input.Position = 0L;

                        var loadOptions = new Aspose.Slides.LoadOptions()
                        {
                            OnlyLoadDocumentProperties = true
                        };

                        using (var presentation = new Aspose.Slides.Presentation(input, loadOptions))
                        {
                            presentation.Dispose();
                        };

                        canHandle = true;
                    }
                    catch (Exception)
                    {
                    }

This is not ideal and we were wondering if there are other ways to check this with the latest of Aspose.Slides similar to utilities like Aspose.Words.FileFormatUtil.DetectFileFormat(input) or even the Aspose.CAD.Image.CanLoad(input)?

Thank you!

@gwert,

I have observed your requirements and have created an issue with ID SLIDESNET-41836 in our issue tracking system as new feature request to provide requested support. This thread has been linked with the issue so that you may be notified once the feature will be available.

Hi there,

I see that issue SLIDESNET-41836 is resolved in your system yet I see no details on how to actually detect if Aspose.Slides.NET supports slides file formats in the 20.6 version of the component.

Can you please add more details here?

Thank you!

@gwert,

We propose you to please use the following suggestions on your end to serve the purpose.

IPresentationInfo info1 = PresentationFactory.Instance.GetPresentationInfo("pres.pptx");
Console.WriteLine(info1.LoadFormat);

if (info1.LoadFormat != LoadFormat.Unknown)
{
    Console.WriteLine("Can handle");
}

IPresentationInfo info2 = PresentationFactory.Instance.GetPresentationInfo("pres.odp");
Console.WriteLine(info2.LoadFormat);

IPresentationInfo info3 = PresentationFactory.Instance.GetPresentationInfo("pres.ppsx");
Console.WriteLine(info3.LoadFormat);

Thank you for sharing the code!

@gwert,

I hope it will work on your end.