Free Support Forum - aspose.com

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

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

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:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/aspose.words.saving.saveoptions.pdfexportimagesfolder.html

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:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/howto-convert-a-document-to-pdf.html

Best regards.