Solved

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

Posted on 2010-11-09
3
1,326 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

914 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

17 Experts available now in Live!

Get 1:1 Help Now