How to Detect a File Format and Check if the File is Encrypted

Contents
[ ]

The following sample code illustrates how to detect a file format (using the file path) and check its extension. You can also determine whether the file is encrypted.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
//Detect file format
FileFormatInfo info = FileFormatUtil.DetectFileFormat(dataDir + "Book1.xlsx");
//Gets the detected load format
Console.WriteLine("The spreadsheet format is: " + FileFormatUtil.LoadFormatToExtension(info.LoadFormat));
//Check if the file is encrypted.
Console.WriteLine("The file is encrypted: " + info.IsEncrypted);