PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index PDFsharp - moved to http://forum.pdfsharp.net/
Please visit the new PDFsharp forum at http://forum.pdfsharp.net/
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Response.Write Problem (Saving pdf to memory Stream) Help!!

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/
View previous topic :: View next topic  
Author Message
matthewb



Joined: 30 Dec 2008
Posts: 7

PostPosted: Mon Feb 23, 2009 2:13 pm    Post subject: Response.Write Problem (Saving pdf to memory Stream) Help!! Reply with quote

Below is working code which does what I want to do but I want to improve it. When I click on a button on my web page the method below runs. It creates the pdf (not shown below) and then saves it on my server. Next it makes a box appear on screen allowing a user to open the file or choose where to save it which is great.

Now the problem..........

Since I will have many users accessing my site this method will not be great as many users will keep changing the pdf contents so when a user runs the method they may get the wrong contents as someone else may have run the method at the same time creating a differnet pdf. I am a web developer and usually I save a file to a 'memorystream 'or a 'file stream' so each user would save their pdf locally rather than on a server where users would change it. The problem is everytime i write code to save the pdf to a memory stream and try to use response.write an error keeps appearing saying corrupt file. Can anyone please show me how it can be done using c#.net? Also does this website take paypal donations as I would willingly donate as this software is fantastic many thanks Matt



outputPdf.Save(filename);
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=apdf.pdf");
Response.Charset = "";
Response.ContentType = "application/vnd.pdf";
Response.WriteFile(filename);
Response.End();
Back to top
View user's profile Send private message
magick_67



Joined: 05 Jan 2009
Posts: 3

PostPosted: Mon Feb 23, 2009 4:09 pm    Post subject: Reply with quote

Dude, this works great for me. I call the object that makes the pdf and return it in a stream.

PdfDocument PDoc = clsPdf.GenerateProductSheetPDF(ProductList);
MemoryStream stream = new MemoryStream();
PDoc.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();

Enjoy!
Back to top
View user's profile Send private message Yahoo Messenger
matthewb



Joined: 30 Dec 2008
Posts: 7

PostPosted: Tue Feb 24, 2009 9:40 am    Post subject: Reply with quote

Thank you!!!!. It was the binary write I was missing out when I was doing it. Thank yoiu very much
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/ All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © phpBB Group. Hosted by phpBB.BizHat.com


Start Your Own YouTube Clone

Free Web Hosting | Free Forum Hosting | FlashWebHost.com | Image Hosting | Photo Gallery | FreeMarriage.com

Powered by PhpBBweb.com, setup your forum now!
For Support, visit Forums.BizHat.com