Free Support Forum - groupdocs.com

Protect Word file with password C#

I have added this license. it works for watermark but when i add password using below code it added evaluation version message.

public static bool ProtectDoc(string FilePath, string OutputPath, string Password)
{
try
{
GroupDocs.Merger.License lic = new GroupDocs.Merger.License();
lic.SetLicense(“cft.gd.lic”);

            using (FileStream fs = new FileStream(FilePath, FileMode.Open))
            {

                AddPasswordOptions options = new AddPasswordOptions(getFileFormat(FilePath), Password);
                GroupDocs.Merger.Domain.Result.DocumentResult result = new DocumentHandler().AddPassword(fs, options);

                fs.Close();
                Stream documentStream = result.Stream;
                var filestream = File.Create(OutputPath);

                documentStream.CopyTo(filestream);
                documentStream.Close();
                filestream.Close();

            }
            return true;
        }
        catch (GroupDocs.Merger.Exceptions.GroupDocsMergerException ex1)
        {
            if (ex1.Message == "Password already exists. Use UpdatePassword")
            {
                throw new Exception("Document is already Protected");
            }
            throw;
        }

        catch (Exception)
        {

            throw;
        }

    }

This Topic is created by atirtahir3 using Email to Topic tool.

@tilankak

Your license works fine at our end with below code. Are you facing this issue using API version 20.5?

License lic = new License();
lic.SetLicense(@"D:/cft.gd.lic");
string filePath = @"D:/Requirements for the Law Trust.docx";
string filePathOut = @"D:/output.docx";
AddPasswordOptions addOptions = new AddPasswordOptions("123");
using (Merger merger = new Merger(filePath))
{
      merger.AddPassword(addOptions);
      merger.Save(filePathOut);
} 

Here’s the issue. AddPasswordOptions takes only one argument (in API version 20.5). Have a look at this screenshot.JPG.png (7.7 KB), you can further explore this documentation article in order to add password protection to a document.

Note: Please always share license file (whenever necessary) in private message.

I have updated to 20.6 but still it add the message.
I can send you the project with license to private message

1 Like

@tilankak

Yes, please send the project along-with licence file in private message.

what is your email

@tilankak

We could reproduce the issue using sample project you shared in private message. Hence, it has been logged in our internal issue tracking system with ID MERGERNET-892 . We’ll notify you in case of any update.

@tilankak

We’ve an update on MERGERNET-892. Please download this example project.zip (568.1 KB), it contains other GroupDocs and Aspose APIs as well (that you were using in your project). You have to place license file in example project\GroupDocs.Merger.Examples.CSharp.Framework\bin\Debug\Resources path. Let us know if you face same issue using this application.

Here I have added my license . when I add as example there is still evolution messagecft.gd.zip (793 Bytes)

Here I have added my license to project as example but still there is a evolution message.
I cannot attached the project here it is too big

here is the link to project with license added

@tilankak

Thank you for the sample project. We’ll now investigate it and share our findings with you.

@tilankak

We investigated the project you shared earlier and it’s been noticed that you are applying Aspose.Total Product Family license. Please note that this license is only valid for Aspose APIs. For GroupDocs APIs, you have to apply GroupDocs.Total Product Family license.
So, getting evaluation mark in such a case is an expected behavior. If you are intended to use both (Aspose and GroupDocs) APIs in a single project, you have to either apply separate licenses or purchase Conholdate.Total license that works with both product families APIs.