PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Jul 15, 2024 2:20 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Issue with Clock Sample
PostPosted: Fri Sep 05, 2014 10:31 pm 
Offline

Joined: Fri Sep 05, 2014 10:27 pm
Posts: 2
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.


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 08, 2014 7:46 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Sep 09, 2014 3:50 pm 
Offline

Joined: Fri Sep 05, 2014 10:27 pm
Posts: 2
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......


Top
 Profile  
Reply with quote  
PostPosted: Tue Sep 09, 2014 4:20 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 56 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group