Aspose.Words - Errors after upgrading to .NET8, and Aspose 25.9.0

Hi,

I have a method where I am trying to save the document with custom properties. I am using the document.Save() to achieve it.

After updating to .NET 8, I am getting the following error for document Save methods.
No overload for method ‘Save’ takes 4 arguments
Code to save document:

public static Aspose.Words.Saving.SaveOutputParameters SaveWithSensitivity(
Aspose.Words.Document document,
HttpResponse response,
string fileName,
Aspose.Words.ContentDisposition contentDisposition,
Aspose.Words.Saving.SaveOptions saveOptions
) {
document.CustomDocumentProperties.Add(“Label_Name”,“Sensitive_Label”)
document.CustomDocumentProperties.Add(“Label_Type”,“Sensitive”)
return document.Save(response, fileName, contentDisposition, saveOptions);
}

Please let me know if you need anything else.
Thanks

@rpmati

It appears that after upgrading to .NET 8 and Aspose.Words 25.9.0, you are encountering an issue with the Save method due to a parameter count mismatch. The error message indicates that the method you are trying to call does not accept four arguments.

In the latest versions, the Save method for the Document class may have changed its overloads. You should verify the updated documentation for the correct method signature.

Here’s a possible adjustment to your code:

public static Aspose.Words.Saving.SaveOutputParameters SaveWithSensitivity(
    Aspose.Words.Document document,
    HttpResponse response,
    string fileName,
    Aspose.Words.Saving.SaveOptions saveOptions
) {
    document.CustomDocumentProperties.Add("Label_Name", "Sensitive_Label");
    document.CustomDocumentProperties.Add("Label_Type", "Sensitive");

    // Check the correct overload for Save method
    // Example: If the method now only takes 3 parameters
    return document.Save(response, fileName, saveOptions);
}

Make sure to verify the correct parameters for the Save method in the latest Aspose.Words documentation. If the overloads have changed, you may need to adjust your method call accordingly.

If you continue to face issues, consider providing a minimal reproducible example in the Aspose forums for further assistance.

Hi @Professionalize.Discourse

Thanks for the quick response.

The method I am trying to use is from your Aspose.Words documentation. Please refer the below link.
https://reference.aspose.com/words/net/aspose.words/document/save/#save_5

Let me know if I did anything wrong in my implementation

@rpmati This Save method overload is not available in .NET Standard and .NET Core versions. It is available only in .NET Framework versions of Aspose.Words.
https://docs.aspose.com/words/net/xamarin-and-net-standard-2-0-limitations-and-api-differences/

You can save your document to stream and them sent it to the browser.

There are two options to chose in ContentDisposition, Attachment or Inline. How to achieve both? Is it possible to leverage HttpResponse from Microsoft.AspNetCore.Http namespace to achieve it. Can you provide an example on this scenario.

@rpmati Saving to response works as the following code:

using (MemoryStream stream = new MemoryStream())
{
    doc.Save(stream, SaveFormat.Pdf);
    Response.Clear();

    //Specify the document type.
    Response.ContentType = "application/pdf";

    //Other options:
    //Response.ContentType = "text/plain"
    //Response.ContentType = "text/html"
    //Specify how the document is sent to the browser.
    Response.AddHeader("content-disposition", "attachment; filename=MyDocument.pdf");

    //Another option could be:
    //Response.AddHeader("content-disposition", "inline; filename=out.doc");
    //Get data bytes from the stream and send it to the response.
    byte[] bytes = stream.GetBuffer();

    Response.BinaryWrite(bytes);
    Response.End();
}

So you can implement the same approach in your code.