473,378 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Send stream but not end app?

dgk
This code sends a PDF but ends the application. How can I send the
stream but keep the session running? Thanks.

Dim ms As New system.io.memorystream
Dim document As New iTextSharp.text.Document
Dim writer As iTextSharp.text.pdf.PdfWriter =
iTextSharp.text.pdf.PdfWriter.GetInstance(document , ms)
document.open()
document.Add(New iTextSharp.text.Paragraph("Hello World"))
document.close()
Response.ClearContent()
Response.ContentType = "application/pdf"
Response.BinaryWrite(ms.GetBuffer)
Response.End()
Dec 4 '06 #1
3 3342
It doesn't "end the application", it just ends the Response output stream for
that page. Have you tried a server.transfer or Response.Redirect to a
"Success page" instead?
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"dgk" wrote:
This code sends a PDF but ends the application. How can I send the
stream but keep the session running? Thanks.

Dim ms As New system.io.memorystream
Dim document As New iTextSharp.text.Document
Dim writer As iTextSharp.text.pdf.PdfWriter =
iTextSharp.text.pdf.PdfWriter.GetInstance(document , ms)
document.open()
document.Add(New iTextSharp.text.Paragraph("Hello World"))
document.close()
Response.ClearContent()
Response.ContentType = "application/pdf"
Response.BinaryWrite(ms.GetBuffer)
Response.End()
Dec 4 '06 #2
dgk
On Mon, 4 Dec 2006 14:59:00 -0800, Peter Bromberg [C# MVP]
<pb*******@yahoo.nospammin.comwrote:
>It doesn't "end the application", it just ends the Response output stream for
that page. Have you tried a server.transfer or Response.Redirect to a
"Success page" instead?
Peter
I tried response.redirect, that cancelled the pdf. Server.Transfer
also cancels the pdf. I seem to have a choice of not sending the pdf,
and returning to default.aspx, or sending the pdf and ending the app.
By ending the app, I mean that no browser window is open and Visual
Studio drops out of run and back into edit:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim ms As New memorystream
Dim document As New iTextSharp.text.Document
Dim writer As iTextSharp.text.pdf.PdfWriter =
iTextSharp.text.pdf.PdfWriter.GetInstance(document , ms)
document.open()
document.Add(New iTextSharp.text.Paragraph("Hello World"))
document.close()
Response.ClearContent()
Response.ContentType = "application/pdf"
Response.BinaryWrite(ms.GetBuffer)
Response.End()
'Response.Redirect("default.aspx")
Server.Transfer("default.aspx")
End Sub

The browser opens the PDF, and there is no way to get back to the
page.
Dec 5 '06 #3
dgk
On Tue, 05 Dec 2006 08:47:48 -0500, dgk <dg*@somewhere.comwrote:
>On Mon, 4 Dec 2006 14:59:00 -0800, Peter Bromberg [C# MVP]
<pb*******@yahoo.nospammin.comwrote:
>>It doesn't "end the application", it just ends the Response output stream for
that page. Have you tried a server.transfer or Response.Redirect to a
"Success page" instead?
Peter

I tried response.redirect, that cancelled the pdf. Server.Transfer
also cancels the pdf. I seem to have a choice of not sending the pdf,
and returning to default.aspx, or sending the pdf and ending the app.
By ending the app, I mean that no browser window is open and Visual
Studio drops out of run and back into edit:
Ah, got it. The problem was that it worked ok if the user saved the
pdf and then opened it; that opened the PDF in a new window. However
just choosing to open it without saving it used the same browser
session, without even a back button, so closing the PDF closed the
session.

However, adding this line:

Response.AddHeader("content-disposition", "attachment;
filename=file.pdf")

causes the pdf to open in a new browser window even on the original
open. The only problem is a slight flash of a window opening, which is
fine by me. Thanks to a post by "Random" the final code then:

With Response
.Buffer = True
.ClearContent()
.ClearHeaders()
.ContentType = "application/pdf"
.AddHeader("content-disposition", "attachment;
filename=file.pdf")
.BinaryWrite(ms.GetBuffer) ' this is the memory stream of bytes
containing the pdf
.End()
End With
Dec 5 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fatih BOY | last post by:
Hi, I want to send a report from a windows application to a web page like 'report.asp' Currently i can send it via post method with a context like local=En&Username=fatih&UserId=45&Firm=none...
4
by: zhimin | last post by:
Hi, I'm writing a program to send large file(100m) through dotnet using TCPListener & TCPClient, I'm sending the file with a ask and response loop: 1. Client send a flag 1 to server indicate it...
3
by: Dirk Reske | last post by:
Hey, I have following struct: struct Packet { string Command; string Args; byte Data; }
9
by: eswanson | last post by:
I have a web page I need to post a file plus some other fields to it. How can I do this from a asp.net page. I know I can send individual fields to the other page, but how do I send a file to the...
1
by: Matt | last post by:
We have an Intermec stationary computers setup to basically clock people in and out... I have code running (borrowed from Planet Source Code and modified to suit) to receive packets from these...
2
by: abhay | last post by:
hi,i m interfacing gsm modem to my microcontroller.i need to send sms through it. i am using AT commands for that.the command to send sms (AT+ CMGS) terminates with ctrl-Z.now in my program i hav...
3
by: BuddyWork | last post by:
Hello, Could someone please explain why the Socket.Send is slow to send to the same process it sending from. Eg. Process1 calls Socket.Send which sends to the same IP address and port, the...
14
by: eliss.carmine | last post by:
I'm using TCP/IP to send a Bitmap object over Sockets. This is my first time using C# at all so I don't know if this is the "right" way to do it. I've already found out several times the way I was...
1
by: kimtherkelsen | last post by:
Hi, I want to send XML data from a server to some clients over a network connection using the TCP/IP protocol. If I send the XMLs as byte arrays I need to insert header information in the data to...
3
by: Newbie27 | last post by:
Hi everyone. I am new to programming and trying to learn as I go however am struggling here and any assistance please I greatly appreciate. I am trying to send hardcoded xml tags to a server that...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.