Solved

asp.net: Create a virtual file programmatically, then download it to the clients computer.

Posted on 2010-11-09
3
1,320 Views
Last Modified: 2012-05-10
I'm trying to programmatically create a .txt file then download it a client's computer. The only condition is that I do not want to save the file to the server; everything has to be virtual.

Here is the Pseudo-code to give you a better idea of what I'm trying to do:

dim file as file
file.type = ".txt."
file.contents("some text")
'Prompt user to then download this file

Really, I'm just expecting a "point in the right direction" rather than an answer. I prefer VB.NET but C# is fine.


0
Comment
Question by:dcmorrell
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
kolakanuru1 earned 500 total points
Comment Utility

        Dim buffer As Byte()
        Using memoryStream = New System.IO.MemoryStream()
            buffer = Encoding.[Default].GetBytes("Hello, How are you doing") ' place anything you want here
            memoryStream.Write(buffer, 0, buffer.Length)
            Response.Clear()
            Response.AddHeader("Content-Disposition", "attachment; filename=test.txt")
            Response.AddHeader("Content-Length", memoryStream.Length.ToString())
            Response.ContentType = "text/plain"
            memoryStream.WriteTo(Response.OutputStream)
        End Using
        Response.End()
0
 

Author Closing Comment

by:dcmorrell
Comment Utility
Thanks.
Is there a guide or tutorial page out there that could elaborate on this process?

I'll use it, but I'd like to have a comprehensive understanding of what I'm doing.
0
 
LVL 3

Expert Comment

by:kolakanuru1
Comment Utility
Go through response object in MSDN.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

8 Experts available now in Live!

Get 1:1 Help Now