473,386 Members | 1,830 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,386 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 2353
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.