Return a Stream of XML Data that elicits a "SAVE/RUN" Dialog

Return a Stream of XML Data that elicits a "SAVE/RUN" Dialog

am 08.10.2004 18:35:44 von John Kotuby

I am working on an ASP site that currently returns user requested data from
a SQL Server 2000 database in different formats (Excel, Print, etc.). I am
adding XML as a format. I have successfully written code that returns a
stream of XML data in the form of a Data Island, which works well for users
of IE. I am now attempting to return the same data in a way that elicits the
typical MS Dialog that pops up when a file download is being requested,
allowing the user to either Save to file or Run. I am presuming that for IE
users, selecting Run will neatly display the XML in the browser window.

I suppose that I can save the XML data which I currently have in a Stream
object in the ASP page to a file and then force a file download. This seems
too complicated and would involve file handling issues at the Server side,
which I wish to avoid. There must be a way to send that stream so that a
dialog appears without first saving it to file. Currently the XML just
appears in the browser window, which is not the intention. Here is a code
that I am using to produce the Data Island. I just want to modify it to
elicit the Dialog.
------------------------------------------------------------ ---------------------
sQuery = ""
sQuery = sQuery & ""
sQuery = sQuery & "exec PLSPCOM_PCD_QUERY_BY_DECK "&deckid&"
"
sQuery = sQuery & "
"

adoStreamQuery.Open ' Open the command
stream so it may be written to
adoStreamQuery.WriteText sQuery, adWriteChar ' Set the input cmd
stream's text with query str
adoStreamQuery.Position = 0 ' Reset the position in the
stream, otherwise it will be at EOS

Set adoCmd.CommandStream = adoStreamQuery ' Set the cmd to the
input stream
adoCmd.Dialect = "{5D531CB2-E6Ed-11D2-B252-00C04F681B71}" ' Set the
dialect
adoCmd.Properties("Output Stream") = response ' Set command's output
stream opened
adoCmd.Execute , , adExecuteStream ' Execute filling up
the output stream.
------------------------------------------------------------ ----------------------

I have tried adding header information prior to executing the ADO command to
elicit the dialog, probably incorrectly for XML, without luck. That method
had worked in another ASP page where I open a disk file (a self_extracitng
zip) to a stream object and use BinaryWrite. Here is that code below..

------------------------------------------------------------ ------------
'Set the content type to the specific type that you are sending.
Response.ContentType = "application/save"
'AddHeader supplies the correct filename, default is name of page
TransferKey.asp
Response.AddHeader "content-disposition", "filename=plkey.exe"

Const adTypeBinary = 1
Dim strFilePath

strFilePath = "D:\HTTP\POWERLIST\PLKEY\plkey.exe" 'This is the path to
the file on disk.

Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath

Response.BinaryWrite objStream.Read
------------------------------------------------------------ ---------------------

I have also tried placing the results of the ADO command into a stream
object and then using Response.BinaryWrite, but that results in errors:

Error Type:
ADODB.Command (0x800A0C93)
Operation is not allowed in this context.

Which points to the line "adoCmd.Execute , , adExecuteStream " below......
------------------------------------------------------------ --------------
Set outStrm = CreateObject("ADODB.Stream") 'Create the output stream
outStrm.Open
outStrm.Type = 1 'adTypeBinary

adoCmd.Properties("Output Stream") = outStrm 'Set command's output
stream

Response.ContentType = "application/save"
Response.AddHeader "content-disposition", "filename=decktext.xml"

adoCmd.Execute , , adExecuteStream 'Execute the command

Response.BinaryWrite outStrm.Read
------------------------------------------------------------ ---------------
When I comment out the line that sets the stream type " outStrm.Type = 1"
Then I get
Error Type:
ADODB.Stream (0x800A0C93)
Operation is not allowed in this context.

Which now points to the line "Response.BinaryWrite outStrm.Read"

I am stuck ...please help.
I am sure there is a simple and elegant way to accomplish sending the stream
of XML so that it elicits a Save/Run dialog, but I am not finding it.

Thanks in advance.