View previous topic :: View next topic |
Author |
Message |
matthewb
Joined: 30 Dec 2008 Posts: 7
|
Posted: Mon Feb 23, 2009 2:13 pm Post subject: Response.Write Problem (Saving pdf to memory Stream) Help!! |
|
|
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 |
|
|
magick_67
Joined: 05 Jan 2009 Posts: 3
|
Posted: Mon Feb 23, 2009 4:09 pm Post subject: |
|
|
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 |
|
|
matthewb
Joined: 30 Dec 2008 Posts: 7
|
Posted: Tue Feb 24, 2009 9:40 am Post subject: |
|
|
Thank you!!!!. It was the binary write I was missing out when I was doing it. Thank yoiu very much |
|
Back to top |
|
|
|