Solved

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

Posted on 2010-11-09
3
1,333 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
ID: 34097352

        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
ID: 34115317
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
ID: 34122314
Go through response object in MSDN.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

821 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