[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2010-11-09
3
Medium Priority
?
1,368 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 2000 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

829 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