How to save a document to database using MemoryStream or Response.OutputStream?

hi all,
i have a gridview, when i select one row and click the button A, it will generate a PDF document, save it to database and popup/display it to users.  how to achieve it?

thanks a lot
viola
Response.ContentType = "application/pdf";
        Response.AddHeader("Content-Disposition", "inline;filename=EmailConfirmation.pdf");
        MemoryStream stream = new MemoryStream();
        InitPDF(stream ); 
foreach (GridViewRow row in gvEmail.Rows)
        {
            CheckBox cb = (CheckBox)row.FindControl("cbLetter");
            if (cb.Checked)
            {
                AddPage(row); //generate PDF file
            }
        }
        stream.WriteTo(Response.OutputStream); //if i use this method, it pops up a window to ask me to save the file. but i don't want to do this, i want to directly pops up the file to display it to user. how to do that?
        document.Close();
        
        Response.End();
}
 
private void InitPDF(Stream stream)
    {
        FontFactory.RegisterDirectories();
        Arial_8 = FontFactory.GetFont("Arial", 8, Font.NORMAL);
        Arial_9_bold = FontFactory.GetFont("Arial", 9, Font.BOLD);
        Arial_12 = FontFactory.GetFont("Arial", 12, Font.NORMAL);
        Arial_12_bold = FontFactory.GetFont("Arial", 12, Font.BOLD);
        Arial_12_underline = FontFactory.GetFont("Arial", 12, Font.UNDERLINE);
        document = new Document(PageSize.A4, 60, 60, 60, 90);
 
        writer = PdfWriter.GetInstance(document, stream);
        writer.PageEvent = new PDFTemplate(document, true, false, false);
        writer.SetEncryption(true, null, "aaa", PdfWriter.AllowPrinting);	// disable copy
 
        document.AddAuthor("tester");
        document.AddCreator("");
        document.AddSubject("");
        document.AddTitle("Email Confirmation");
 
        document.Open();
    }

Open in new window

LVL 6
viola123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Anurag ThakurTechnical ManagerCommented:
hi regarding the PDF popping up the dialog see the following links
http://www.velocityreviews.com/forums/t117955-file-open-and-save-dialog-poping-up-while-opening-pdf.html
http://bytes.com/forum/thread331070.html

saving the pdf file to sql server check the follwoing links
the link shows how to save an image file to the sql server but the same can be converted to pdf too
http://www.codeproject.com/KB/web-image/PicManager.aspx
0
viola123Author Commented:
hi,
i tried the solutions, they do not work for me. the file download window is still be popped up to ask you to save the PDF file.
0
viola123Author Commented:
Hi,
now i have to create two documents, one is used to save to database(this one using MemoryStream), the other one is used to pop up(this one using Response.OutputStream). it works quite well.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.