Solved

Unable to trasmit MemoryStream file to HttpResponse

Posted on 2014-01-17
2
368 Views
Last Modified: 2014-01-17
I have the following code which is working well if I send a Crystal report to it using the ExportToStream() method.  Unfortunately if I run the same code using a MemoryStream object containing xml.  What happens is the XML is output but that is followed by the entire webpage.  The code below is followed by an example output.

        static public void SendFile(HttpResponse Response, Stream file, string FileName)
        {
            Response.ContentType = "application/octet-stream";
            Response.AppendHeader("content-disposition", "attachment; filename=" + FileName);
            file.CopyTo(Response.OutputStream);
            Response.OutputStream.Flush();            
        }

Open in new window



<?xml version="1.0" encoding="utf-8"?>
<Root>
  <File>
    <Orders>
      <Order>
        <Order-Number>1796</Order-Number>
        <Order-Date>10/01/2014</Order-Date>
        <Ship-From-Date />
        <Ship-To-Date />
        <Bill-to-Id />
        <Bill-to-Name />
        <Bill-to-Address-1>test</Bill-to-Address-1>
        <Bill-to-Address-2>test3</Bill-to-Address-2>
        <Bill-to-City>test</Bill-to-City>
        <Bill-to-State></Bill-to-State>
        <Bill-to-Zip></Bill-to-Zip>
        <Bill-to-Country />
        <Bill-to-Phone />
        <Bill-to-Email />
      </Order>
    </Orders>
  </File>
</Root>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
....Blah blah...
</head>

<body>
....Blah blah...
</body>
</html>
0
Comment
Question by:canuckconsulting
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 23

Accepted Solution

by:
Snarf0001 earned 500 total points
ID: 39790097
Response.OutputStream.Flush();            
Response.End();
0
 

Author Closing Comment

by:canuckconsulting
ID: 39790226
Thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question