Solved

Unable to trasmit MemoryStream file to HttpResponse

Posted on 2014-01-17
2
357 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
This video teaches users how to migrate an existing Wordpress website to a new domain.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

770 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