Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

send generated RTF file directly to browser

Status
Not open for further replies.

sfenx

Programmer
Feb 23, 2001
81
BE
I generated an RTF (richtext) file with ASP and I want my browser to open it with a RTFreader (like Word) that is installed on my computer. I've read a lot of articles on how to do this, but they always write the file to the server first. My question : is there a way to send my RTFgenerated file directly to the browser WITHOUT writing it first to the server (so within 1 asp-page) ? I think it has something to do with the response.addheader and response.contenttype, but I'm not sure if it's possible at all. Perhaps there's a way by adding an new extension (rtf) in the Application Mappings of IIS?

Romme
 
How about something like this? I usually get stuff from a file, but I've modified this code to work with bytes you've crammed into the variable MyRTFStuff:

<%@ LANGUAGE = VBScript %>
<%
Dim objStream, MyRTFStuff

On Error Resume Next

'Create a stream object
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1 'adTypeBinary
objStream.Open
objStream.Write MyRTFStuff 'be sure to put stuff in this variable first

'Output the contents of the stream object
Response.ContentType = "application/rtf"
Response.BinaryWrite objStream.Read
objStream.Close
set objStream = Nothing

%>
 
This looks like the perfect solution, but I have a problem with
Code:
objStream.Write MyRTFStuff
. Do I have to put binary data in the MyRTFStuff variable? I tryed a lot but nothing worked. This is the error message I get : "ADODB.stream - arguments are of the wrong type, fall out of reach or are in conflict
 
How are you generating your binary data? How are you storing it?
 
This is just the problem I'm dealing with. All I want to do is send a string (i.e. 'this is my test') to the Stream object. I tryed the Request.BinaryRead, but that doesn't work in this case. What do I have to do to send binary data to the Stream object without using an external file?
 
Well, it turns out that you don't even need all this stream crap if you are delivering the content via the web. Just do this:

<%@ LANGUAGE = VBScript %>
<%


Response.AddHeader "content-disposition", "attachment; filename=test.rtf"
Response.ContentType = "application/rtf"
Response.Write "Hello there!"

%>

Whatever you Response.Write goes to your browser, which will fire up your rtf reader.

Hope this helps!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top