Free Support Forum - aspose.com

Response.OutputStream

Hi there

I want to stream my word document on the http response outputstream, but I get an exception:

NotSupportedException: Specified method is not supported.]
System.Web.HttpResponseStream.set_Position(Int64 value) +28
?.?.?(Stream ?) +300
?.?.?(Document ?, Stream ?, String ?) +50
Aspose.Words.Document.Save(Stream stream, SaveFormat fileFormat) +61

Some of the code I am using:

Response.Buffer = true;
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentEncoding = Encoding.GetEncoding("ISO-8859-1");
Response.ContentType = "application/msword";

Response.AddHeader("Content-Disposition", "attachment;filename=xxx.doc");

Document doc = new Document("adoc.doc");

// add stuff to document...

doc.Save(Response.OutputStream, SaveFormat.FormatDocument);

What could I be doing wrong?

Thanks,

Peter

I have found out that there is another method

doc.save(string filename, SaveFormat fileformat, SaveType savetype, HttpResponse response)

and this might be fine, except I have a general "service" which wants to stream on any supplied output stream - it is independent of Http, and doesn't even know it runs in a web context, just that it shoud generate a document and stream it.

How can I achieve this? For example, with Aspose.Pdf I can stream on HttpResponse output stream like this:

Pdf pdf = new Pdf();
pdf.BindFO(xmlDoc, xsltPath);
pdf.Save(outStream);

Where outStream could be Response.OutputStream.

Thanks,

Peter

To workaround you can save to MemoryStream first using Document.Save method and then copy the contents of the MemoryStream to HTTP response.

Best regards,