diff --git a/Word-document/Identify-Word-document-is-Encrypted-or-not/.NET/Identify-Word-document-is-Encrypted-or-not.sln b/Word-document/Identify-Word-document-is-Encrypted-or-not/.NET/Identify-Word-document-is-Encrypted-or-not.sln new file mode 100644 index 00000000..f700b326 --- /dev/null +++ b/Word-document/Identify-Word-document-is-Encrypted-or-not/.NET/Identify-Word-document-is-Encrypted-or-not.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.37012.4 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Identify-Word-document-is-Encrypted-or-not", "Identify-Word-document-is-Encrypted-or-not\Identify-Word-document-is-Encrypted-or-not.csproj", "{54A935D7-C09A-697B-0D61-C7AAC43F2784}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {54A935D7-C09A-697B-0D61-C7AAC43F2784}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {54A935D7-C09A-697B-0D61-C7AAC43F2784}.Debug|Any CPU.Build.0 = Debug|Any CPU + {54A935D7-C09A-697B-0D61-C7AAC43F2784}.Release|Any CPU.ActiveCfg = Release|Any CPU + {54A935D7-C09A-697B-0D61-C7AAC43F2784}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FCABE1DE-F4AA-4316-AEF1-3C5C985F9610} + EndGlobalSection +EndGlobal diff --git a/Word-document/Identify-Word-document-is-Encrypted-or-not/.NET/Identify-Word-document-is-Encrypted-or-not/Data/Template.docx b/Word-document/Identify-Word-document-is-Encrypted-or-not/.NET/Identify-Word-document-is-Encrypted-or-not/Data/Template.docx new file mode 100644 index 00000000..6980dc5d Binary files /dev/null and b/Word-document/Identify-Word-document-is-Encrypted-or-not/.NET/Identify-Word-document-is-Encrypted-or-not/Data/Template.docx differ diff --git a/Word-document/Identify-Word-document-is-Encrypted-or-not/.NET/Identify-Word-document-is-Encrypted-or-not/Identify-Word-document-is-Encrypted-or-not.csproj b/Word-document/Identify-Word-document-is-Encrypted-or-not/.NET/Identify-Word-document-is-Encrypted-or-not/Identify-Word-document-is-Encrypted-or-not.csproj new file mode 100644 index 00000000..d73ee07e --- /dev/null +++ b/Word-document/Identify-Word-document-is-Encrypted-or-not/.NET/Identify-Word-document-is-Encrypted-or-not/Identify-Word-document-is-Encrypted-or-not.csproj @@ -0,0 +1,19 @@ + + + + Exe + net8.0 + Identify-Word-document-is-Encrypted-or-not + + + + + + + + + Always + + + + diff --git a/Word-document/Identify-Word-document-is-Encrypted-or-not/.NET/Identify-Word-document-is-Encrypted-or-not/Program.cs b/Word-document/Identify-Word-document-is-Encrypted-or-not/.NET/Identify-Word-document-is-Encrypted-or-not/Program.cs new file mode 100644 index 00000000..ea75bb26 --- /dev/null +++ b/Word-document/Identify-Word-document-is-Encrypted-or-not/.NET/Identify-Word-document-is-Encrypted-or-not/Program.cs @@ -0,0 +1,37 @@ +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using System; +using System.IO; + +namespace Identify_Word_document_is_Encrypted_or_not +{ + class Program + { + static void Main(string[] args) + { + //Creates a new Word document. + using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + { + Console.WriteLine(IsEncrypted(fileStreamPath)); + } + } + public static string IsEncrypted(FileStream fileStream) + { + try + { + //Open the existing Word document. + WordDocument document = new WordDocument(fileStream, FormatType.Docx); + return "Document is not encrypted."; + } + catch (Exception exception) + { + //Return if Word document is encrypted. + if (exception.Message == "Document is encrypted, password is needed to open the document") + { + return exception.Message; + } + } + return "Document is not encrypted."; + } + } +} \ No newline at end of file