Image File cannot be written to the Disk

I have a scenario where I need to return a byte array. This is the code that was used with the earlier version(5.2.2.). As I said earlier, I have to use both the version as I have some users who are not ready for this upgrade. For the user who are ready with this upgrade, I’m using Aspose.Words ver 8.2.1.

The below strategy is used in my middle tier and changing the UI peice is very very risky. Appreciate your help.

The new version errors out when I use the new version. Here the code and error:

public byte[] PdfStream
{
    get
    {
        System.Security.Principal.WindowsImpersonationContext ctx = RemoveASPNETAuthenticationToken();
        try
        {

            MemoryStream memStream = new MemoryStream();
            Document.Save(memStream, SaveFormat.AsposePdf);

            memStream.Seek(0, SeekOrigin.Begin);
            System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
            xmlDoc.Load(memStream);
            Aspose.Pdf.Pdf pdf = new Pdf();
            pdf.BindXML(xmlDoc, null);
            byte[] byteStream;
            using(MemoryStream pdfStream = new MemoryStream())
            {
                pdf.Save(pdfStream);

                byteStream = pdfStream.ToArray();
            }
            return byteStream;
        }
        finally
        {
            // Resume impersonation
            if (ctx != null) ctx.Undo();
        }
    }
}

I’m getting the Error “Image File cannot be written to the Disk…” when I use this method. How can I solve this with the new version of Word.

Hi

Thanks for your request. To fix this problem you should just specify folder where images will be saved. Please see the following link for more information:
https://reference.aspose.com/words/net/aspose.words.saving/pdfsaveoptions/
Also, with the new version of Aspose.Words you can use direct method of PDF conversion (without Aspose.Pdf and saving in intermediate format). Please see the following link to learn more:
https://docs.aspose.com/words/net/convert-a-document-to-pdf/
Best regards.