Solved

Unable to trasmit MemoryStream file to HttpResponse

Posted on 2014-01-17
2
353 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
2 Comments
 
LVL 22

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now