473,386 Members | 1,647 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.

Response.Write/Flush/End

Dan
Hi

I've created a generic 'Report' class that takes a DataView from a DataGrid control and writes it out to the response as a csv file for download. Basically, when a user clicks the download button on the page, this class is instantiated and the download method called. The odd thing is you get the Save/Open dialog popup twice!! Any ideas why? The code look like

public void DownloadDataView(DataView view, Page page

string fileName = view.Table.TableName.ToString()

if (fileName == ""

fileName = "report"
page.Response.BufferOutput = true
page.Response.Clear()
page.Response.ClearContent()
page.Response.ClearHeaders()

page.Response.ContentType = "application/octet-stream"
page.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + ".csv\"")

page.Response.Flush()

//write out column heading
int i = view.Table.Columns.Count

for(int j = 0; j<i; j++

if (j == i -1

page.Response.Write("\"" + view.Table.Columns[j].ColumnName.ToString()
Replace("\"", "'") + "\"\n")

els

page.Response.Write("\"" + view.Table.Columns[j].ColumnName.ToString(
.Replace("\"", "'") + "\",")

page.Response.Flush()

//write out actual dat
foreach(DataRow row in view.Table.Rows

for(int j = 0; j<i; j++
if (j == i -1

page.Response.Write("\"" + row[j].ToString().Replace("\"", "'") + "\"\n")

els

page.Response.Write("\"" + row[j].ToString().Replace("\"", "'") + "\",")


page.Response.End()
Thanks for your help

Dan
Nov 18 '05 #1
1 4451
Never saw this behaviour. I would comment the Flush calls (and even perhaps
the End call) to see what happens.

Patrice
--

"Dan" <an*******@discussions.microsoft.com> a écrit dans le message de
news:54**********************************@microsof t.com...
Hi,

I've created a generic 'Report' class that takes a DataView from a DataGrid control and writes it out to the response as a csv file for
download. Basically, when a user clicks the download button on the page,
this class is instantiated and the download method called. The odd thing is
you get the Save/Open dialog popup twice!! Any ideas why? The code look
like:
public void DownloadDataView(DataView view, Page page)
{
string fileName = view.Table.TableName.ToString();

if (fileName == "")
{
fileName = "report";
}

page.Response.BufferOutput = true;
page.Response.Clear();
page.Response.ClearContent();
page.Response.ClearHeaders();

page.Response.ContentType = "application/octet-stream";
page.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + ".csv\"");
page.Response.Flush();

//write out column headings
int i = view.Table.Columns.Count;

for(int j = 0; j<i; j++)
{
if (j == i -1)
{
page.Response.Write("\"" + view.Table.Columns[j].ColumnName.ToString().
Replace("\"", "'") + "\"\n");
}
else
{
page.Response.Write("\"" + view.Table.Columns[j].ColumnName.ToString()
.Replace("\"", "'") + "\",");
}
}

page.Response.Flush();

//write out actual data
foreach(DataRow row in view.Table.Rows)
{
for(int j = 0; j<i; j++)
{

if (j == i -1)
{
page.Response.Write("\"" + row[j].ToString().Replace("\"", "'") + "\"\n");
}
else
{
page.Response.Write("\"" + row[j].ToString().Replace("\"", "'") + "\",");
}
}
}

page.Response.End();
}

Thanks for your help.

Dan


Nov 18 '05 #2

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

Similar topics

0
by: Copa | last post by:
Hello, I am testing buffering an asp page and Flushing information out to the browser, hence i wrote the code in an asp page that follows this Message Post. The loops are suppose to simulate...
7
by: Jon Spivey | last post by:
Experimenting with response.flush() but can't seem to get it to work. This code <% response.write "<p>started</p>" response.flush() for i = 1 to 10000000 i = i +1 next response.write...
3
by: Gary | last post by:
I am having a strange problem that I cannot solve. I have an asp page that I use for a user to login and gain access to other pages. When the user logs in I set a couple of session variables like...
9
by: Dominic Godin | last post by:
Hi, I have an asp page that does a lot of processing and reports it's finished by printing the word "Success". For example: <% SomeFunction(SomeVar) SomeFunction(SomeVar1) ...
3
by: Jason | last post by:
I am using response.flush in order to display "Please wait" message. The problem is that it takes about 15 to 20 seconds for the message to appear. How can I make this appear as soon as the user...
5
by: Luiz Vianna | last post by:
Guys, I need to send some info to my client while I'm processing some stuff. The flow will be something like : -process -response -process -response .... I imagine to use response.flush...
2
by: David Union | last post by:
Hi. I'm posting this here because I don't know exactly what the best group is. This is for an aspx page with Visual Basic as the code-behind page. I am doing very simple code... in the middle...
0
by: jose.mendez22 | last post by:
I'm trying to fire a pop-up window before I execute a lengthy stored procedure so I may utilize this window as a status window on number of records executed. After my response.write statements...
12
by: Jim Rodgers | last post by:
I have a big asp file that has an error under certain conditions -- totally repeatable. However, it only fails when I set response.buffer = True at the top. WHen I set it False in order to debug...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.