Solved

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

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

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

786 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