GroupDocsGists
10/19/2017 - 11:22 AM

DetectProtection.cs

// For complete examples and data files, please go to https://github.com/groupdocs-metadata/GroupDocs.Metadata-for-.NET
FormatBase format = FormatFactory.RecognizeFormat(Common.MapSourceFilePath(filePath)); 

if(format.Type.ToString().ToLower()=="doc")
{
    // initialize DocFormat
    DocFormat docFormat = new DocFormat(Common.MapSourceFilePath(filePath));

    // determines whether document is protected by password
    Console.WriteLine(docFormat.IsProtected ? "Document is protected" : "Document is protected");
}
else if(format.Type.ToString().ToLower()=="pdf")
{
    // initialize DocFormat
    PdfFormat pdfFormat = new PdfFormat(Common.MapSourceFilePath(filePath));

    // determines whether document is protected by password
    Console.WriteLine(pdfFormat.IsProtected ? "Document is protected" : "Document is protected");
}
else if (format.Type.ToString().ToLower() == "xls")
{
    // initialize DocFormat
    XlsFormat xlsFormat = new XlsFormat(Common.MapSourceFilePath(filePath));

    // determines whether document is protected by password
    Console.WriteLine(xlsFormat.IsProtected ? "Document is protected" : "Document is protected");
}
else if(format.Type.ToString().ToLower()=="ppt")
{
    // initialize DocFormat
    PptFormat pptFormat = new PptFormat(Common.MapSourceFilePath(filePath));

    // determines whether document is protected by password
    Console.WriteLine(pptFormat.IsProtected ? "Document is protected" : "Document is protected");
}
else
{
    Console.WriteLine("Invalid Format.");
}