[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 376
  • Last Modified:

Unable to trasmit MemoryStream file to HttpResponse

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
canuckconsulting
Asked:
canuckconsulting
1 Solution
 
Snarf0001Commented:
Response.OutputStream.Flush();            
Response.End();
0
 
canuckconsultingAuthor Commented:
Thanks!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now