PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Issue with Clock Sample
https://forum.pdfsharp.net/viewtopic.php?f=2&t=2920
Page 1 of 1

Author:  Frankwin [ Fri Sep 05, 2014 10:31 pm ]
Post subject:  Issue with Clock Sample

I'm trying use the code to send a PDF to a browser using the Clock Sample, but there's something missing in the sample and I'm not sure what.

This is the code I use:

// Send PDF to browser
MemoryStream stream = new MemoryStream();
document.Save(stream, false);
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", stream.Length.ToString());
Response.BinaryWrite(stream.ToArray());
Response.Flush();
stream.Close();
Response.End();

I'm getting the error "The name 'Response' does not exist in the current context" on the "Response.Clear()" line.

I tried creating an HttpResponse object called Response, but this needs a TextWriter, which then results in other issues, such as the "OutputStream is not available when a custom TextWriter is used." error message when I change it to on the "Response.BinaryWrite(stream.ToArray());" call.

// Send PDF to browser
MemoryStream stream = new MemoryStream();
document.Save(stream, false);
StreamWriter txt = new StreamWriter(stream);
HttpResponse Response = new HttpResponse(txt);
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", stream.Length.ToString());
Response.BinaryWrite(stream.ToArray());
Response.Flush();
stream.Close();
Response.End();

So what am I missing/doing wrong?

Please help.

Author:  Thomas Hoevel [ Mon Sep 08, 2014 7:46 am ]
Post subject:  Re: Issue with Clock Sample

Frankwin wrote:
So what am I missing/doing wrong?
Are you using the sample source code from the source code package? If not, try that one.

Author:  Frankwin [ Tue Sep 09, 2014 3:50 pm ]
Post subject:  Re: Issue with Clock Sample

Yes that's exactly what I'm using as you can see in the initial piece of code. It's an exact copy/paste from the sample.

// Send PDF to browser
MemoryStream stream = new MemoryStream();
document.Save(stream, false);
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", stream.Length.ToString());
Response.BinaryWrite(stream.ToArray());
Response.Flush();
stream.Close();
Response.End();

I'm getting the error "The name 'Response' does not exist in the current context" on the "Response.Clear()" line. This makes sense as the Response object is never declared anywhere......

Author:  Thomas Hoevel [ Tue Sep 09, 2014 4:20 pm ]
Post subject:  Re: Issue with Clock Sample

Frankwin wrote:
Yes that's exactly what I'm using as you can see in the initial piece of code.
The code snippet doesn't tell me where it's coming from.

Frankwin wrote:
It's an exact copy/paste from the sample.
Response is a member of the base class Page.
You're copy is not exact, there's something wrong with the base class.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/