MemoryStream as input to file download?

I tried using a memorystream as input to an xml file download, so I wouldn't have to create a disk file (to then delete)....

            Response.AddHeader("Content-Disposition", "attachment; filename=" & varFileName)
            Response.ContentType = "text/XML"
            '    Response.WriteFile(varFilePath & varFileName)  < the alt way to do it

            ''---  use memorystream
            varMemTab.Position = 0
            Dim wrkStreamReader As New StreamReader(varMemTab, Encoding.UTF8)
            Dim content As String = wrkStreamReader.ReadToEnd()
            ''---- do the write

....but it gave an http exception error like it was processing the markup in the Response.WriteFile(content) statement.

Might there be a way to make this work?

Any suggestions would be appreciated.


Who is Participating?
nauman_ahmedConnect With a Mentor Commented:
WriteFile save the file to disk. To send the file to browser as a download, you have to download the file as a byte array. See if the following helps:

Re: Force File Download XML Problem

kraffayConnect With a Mentor Commented:
Make sure that your aspx page doesn't have any HTML markup.
codequestAuthor Commented:
Thanks for input.  I'll give that a try a little later and postback.
The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Solar_FlareConnect With a Mentor Commented:
also end the response stream after you have written your file to it

codequestAuthor Commented:
Thanks for input.   Still working my way back to this one.  I'll keep it alive with posts until I fully resolve.
codequestAuthor Commented:
Still working my way back to this...
codequestAuthor Commented:
Still working on this, should get to it soon...
Bob LearnedCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
   Accept: nauman_ahmed {http:#18054518}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

EE Cleanup Volunteer
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.