473,324 Members | 2,257 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Dynamically Creating Text Files

Hi all,

I'm trying to create a text file on the fly for a user of an ASP.NET
application to download. So far the code I have is:

MemoryStream oStream = null; // using System.IO
string contenttype = "text/plain";
string contentdisposition = "filename=report.txt";
oStream = new MemoryStream();
StreamWriter sw = new StreamWriter(oStream);
Response.Clear();
sw.WriteLine("Hello");
Response.ContentType = contenttype;
Response.Buffer= true;
Response.AddHeader("Content-Disposition", contentdisposition);
Response.BinaryWrite(oStream.ToArray());
Response.End();

However I seem to be getting "empty html" instead. Further, the debugger
shows the memorystream as empty when I call writeline on sw.

Any ideas?

Spammy
Nov 19 '05 #1
2 2348
Likely the problem is in not closing the stream. Call sw.Close() after
writing "Hello".

Eliyahu

"spammy" <me@privacy.net> wrote in message
news:38*************@individual.net...
Hi all,

I'm trying to create a text file on the fly for a user of an ASP.NET
application to download. So far the code I have is:

MemoryStream oStream = null; // using System.IO
string contenttype = "text/plain";
string contentdisposition = "filename=report.txt";
oStream = new MemoryStream();
StreamWriter sw = new StreamWriter(oStream);
Response.Clear();
sw.WriteLine("Hello");
Response.ContentType = contenttype;
Response.Buffer= true;
Response.AddHeader("Content-Disposition", contentdisposition);
Response.BinaryWrite(oStream.ToArray());
Response.End();

However I seem to be getting "empty html" instead. Further, the debugger
shows the memorystream as empty when I call writeline on sw.

Any ideas?

Spammy

Nov 19 '05 #2
Likely the problem is in not closing the stream. Call sw.Close() after
writing "Hello".

Eliyahu

"spammy" <me@privacy.net> wrote in message
news:38*************@individual.net...
Hi all,

I'm trying to create a text file on the fly for a user of an ASP.NET
application to download. So far the code I have is:

MemoryStream oStream = null; // using System.IO
string contenttype = "text/plain";
string contentdisposition = "filename=report.txt";
oStream = new MemoryStream();
StreamWriter sw = new StreamWriter(oStream);
Response.Clear();
sw.WriteLine("Hello");
Response.ContentType = contenttype;
Response.Buffer= true;
Response.AddHeader("Content-Disposition", contentdisposition);
Response.BinaryWrite(oStream.ToArray());
Response.End();

However I seem to be getting "empty html" instead. Further, the debugger
shows the memorystream as empty when I call writeline on sw.

Any ideas?

Spammy

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jake Lewis | last post by:
I have an HTML page that loads fine including the .js file <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> <script...
3
by: Ben | last post by:
Hi all - I am having a bit of trouble and thought maybe someone in this group could shed some light. Here's the skinny... I am creating an automated process to import a bunch of text files...
2
by: Duncan Welch | last post by:
Hi, I've got a fairly simple date control, that I'm creating dynamically in my page. The reason for creating it dynamically is that I want the ID to vary, depending on it's situation. The...
2
by: Asha | last post by:
Greetings, I’ve query some data from the table, how can I push it into an excel file and allow user to save it? anyone done this sort of thing before?
2
by: Astra | last post by:
Hi All Creating an rss.xml file dynamically via ASP/ADO/DB, but find errors in the file. Don't think it's an ASP prob to be honest. Think its more to do with the fact that the ampersands are...
4
by: Dica | last post by:
i need to dynamically add a web control to a page without using placeHolder. i'm looping through all the files in a folder and creating a table row as string for each file. the contol is to be...
2
by: robert112 | last post by:
This is quite a hard one guys. ***Some necessary back ground Info*** I have an asp.net 1.1 application that uses a WYSIWYG to return some html created by the user in the admin section of the...
16
by: flip2flik | last post by:
Hi. I am using visual web developer express edition and I am using vb.net as the programming language. I want to create a new aspx file on a button click. I will have a template that the new...
8
by: BillE | last post by:
When I create a control dynamically and it grows according to the content, the control Height property still returns the original default control height instead of the height after expanding. ...
1
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.