Link to home
Start Free TrialLog in
Avatar of canuckconsulting
canuckconsultingFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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>
ASKER CERTIFIED SOLUTION
Avatar of Snarf0001
Snarf0001
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of canuckconsulting

ASKER

Thanks!