public static void Run()
        {
            var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
            var apiInstance   = new SecurityApi(configuration);

            try
            {
                var fileInfo = new FileInfo
                {
                    FilePath = "WordProcessing/password-protected.docx",
                    Password = "******"
                };

                var options = new UpdatePasswordOptions
                {
                    FileInfo    = fileInfo,
                    OutputPath  = "output/update-password.docx",
                    NewPassword = "******"
                };

                var request  = new UpdatePasswordRequest(options);
                var response = apiInstance.UpdatePassword(request);

                Console.WriteLine("Output file path: " + response.Path);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception while calling api: " + e.Message);
            }
        }
Esempio n. 2
0
        public static void Run()
        {
            string filePath    = Constants.SAMPLE_XLSX_PROTECTED;
            string filePathOut = Path.Combine(Constants.GetOutputDirectoryPath(), Constants.SAMPLE_NAME + Path.GetExtension(filePath));

            LoadOptions           loadOptions   = new LoadOptions(Constants.SAMPLE_PASSWORD);
            UpdatePasswordOptions updateOptions = new UpdatePasswordOptions(Constants.SAMPLE_PASSWORD + Constants.SAMPLE_PASSWORD);

            using (Merger merger = new Merger(filePath, loadOptions))
            {
                merger.UpdatePassword(updateOptions);
                merger.Save(filePathOut);
            }

            Console.WriteLine("Source document password was updated successfully.");
            Console.WriteLine($"Check output {filePathOut}.");
        }
        /// <summary>
        /// Update password for document of known format
        /// </summary>
        /// <param name="fileName">source file</param>
        public static void UpdateProtectionForKnownForamtDocs(string fileName)
        {
            //ExStart:UpdateProtectionForKnownForamtDocs
            string sourceFile = CommonUtilities.sourcePath + fileName;
            // Preparing.
            string currentPassword        = "******";
            string newPassword            = "******";
            UpdatePasswordOptions options = new UpdatePasswordOptions(FileFormat.Docx, currentPassword, newPassword);
            Stream openFile = new FileStream(sourceFile, FileMode.Open);

            // Main method.
            DocumentResult result         = new DocumentHandler().UpdatePassword(openFile, options);
            Stream         documentStream = result.Stream;
            var            fileStream     = File.Create(CommonUtilities.outputPath + "OutPut." + FileFormat.Docx);

            documentStream.CopyTo(fileStream);
            documentStream.Close();
            //ExEnd:UpdateProtectionForKnownForamtDocs
        }