473,383 Members | 1,872 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,383 software developers and data experts.

Response with file attached make save/open dialog appear twice

Hi,

I am using the code below to stream a CSV file with the response object.

Dim FileName As String = "Test.csv"
With Web.HttpContext.Current.Response

Web.HttpContext.Current.Response.AddHeader("conten t-disposition",
"attachment; filename=" & FileName)
.Charset = ""
.Write(Output.ToString()) ' Output is a StringBuilder object
with the content to write
.End()
End With

But when this code has been executed, a dialog pops up asking the user
whether to save or open the file. If the user clicks "Open", the dialog pops
up again. After cliking "Open" in the second dialog, the file is opened by
Excel. If the user clicks "Save", the file is saved, and the dialog has only
appeared once.
In the first dialog "Always ask before opening this type of file" is grayed
out - in the second it is enabled, and checked.
Why does the dialog show up twice? Has it something to do with the browser
settings, or what am I doing wrong? I would appreciate any kind of help.

Thanks,
Dorte
Nov 18 '05 #1
4 3645
What about adding a ContentType to the Respone for your .csv
(text/comma-separated-values)

--
Daniel Fisher(lennybacon)
MCP ASP.NET C#
Blog: http://www.lennybacon.com/
"Dorte" <Do***@discussions.microsoft.com> wrote in message
news:06**********************************@microsof t.com...
Hi,

I am using the code below to stream a CSV file with the response object.

Dim FileName As String = "Test.csv"
With Web.HttpContext.Current.Response

Web.HttpContext.Current.Response.AddHeader("conten t-disposition",
"attachment; filename=" & FileName)
.Charset = ""
.Write(Output.ToString()) ' Output is a StringBuilder object
with the content to write
.End()
End With

But when this code has been executed, a dialog pops up asking the user
whether to save or open the file. If the user clicks "Open", the dialog
pops
up again. After cliking "Open" in the second dialog, the file is opened by
Excel. If the user clicks "Save", the file is saved, and the dialog has
only
appeared once.
In the first dialog "Always ask before opening this type of file" is
grayed
out - in the second it is enabled, and checked.
Why does the dialog show up twice? Has it something to do with the browser
settings, or what am I doing wrong? I would appreciate any kind of help.

Thanks,
Dorte

Nov 18 '05 #2
Doesn't seem to work....
I tried adding the line
Web.HttpContext.Current.Response.ContentType = "text/comma-separated-values"
but it doesn't make any difference.

Dorte

"Daniel Fisher(lennybacon)" wrote:
What about adding a ContentType to the Respone for your .csv
(text/comma-separated-values)

--
Daniel Fisher(lennybacon)
MCP ASP.NET C#
Blog: http://www.lennybacon.com/
"Dorte" <Do***@discussions.microsoft.com> wrote in message
news:06**********************************@microsof t.com...
Hi,

I am using the code below to stream a CSV file with the response object.

Dim FileName As String = "Test.csv"
With Web.HttpContext.Current.Response

Web.HttpContext.Current.Response.AddHeader("conten t-disposition",
"attachment; filename=" & FileName)
.Charset = ""
.Write(Output.ToString()) ' Output is a StringBuilder object
with the content to write
.End()
End With

But when this code has been executed, a dialog pops up asking the user
whether to save or open the file. If the user clicks "Open", the dialog
pops
up again. After cliking "Open" in the second dialog, the file is opened by
Excel. If the user clicks "Save", the file is saved, and the dialog has
only
appeared once.
In the first dialog "Always ask before opening this type of file" is
grayed
out - in the second it is enabled, and checked.
Why does the dialog show up twice? Has it something to do with the browser
settings, or what am I doing wrong? I would appreciate any kind of help.

Thanks,
Dorte


Nov 18 '05 #3
Here is the code I use to stream a csv and it opens in excel. This is in my
button click event. I might be doing extra steps, but I know for sure this
works. I create a temporary file, stream the text ( probably your
Output.ToString() ) to this file, then open the file up and read the bytes
then using BinaryWrite to send the bytes to the browser.

You could probably just skip the temp file and convert your string to bytes.

string filename = "Name Of Report.csv";
byte [] bytes = Read file bytes.

Response.ClearHeaders();
Response.Clear();
Response.AddHeader( "Content-Disposition", "inline; filename=" +
filename );
Response.ContentType = "text/csv";
Response.BinaryWrite( bytes );
Response.End();

HTH,

bill

"Dorte" <Do***@discussions.microsoft.com> wrote in message
news:06**********************************@microsof t.com...
Hi,

I am using the code below to stream a CSV file with the response object.

Dim FileName As String = "Test.csv"
With Web.HttpContext.Current.Response

Web.HttpContext.Current.Response.AddHeader("conten t-disposition",
"attachment; filename=" & FileName)
.Charset = ""
.Write(Output.ToString()) ' Output is a StringBuilder object
with the content to write
.End()
End With

But when this code has been executed, a dialog pops up asking the user
whether to save or open the file. If the user clicks "Open", the dialog pops up again. After cliking "Open" in the second dialog, the file is opened by
Excel. If the user clicks "Save", the file is saved, and the dialog has only appeared once.
In the first dialog "Always ask before opening this type of file" is grayed out - in the second it is enabled, and checked.
Why does the dialog show up twice? Has it something to do with the browser
settings, or what am I doing wrong? I would appreciate any kind of help.

Thanks,
Dorte

Nov 18 '05 #4
Great! It works!
Thanks a lot, Bill.

Dorte

"William F. Robertson, Jr." wrote:
Here is the code I use to stream a csv and it opens in excel. This is in my
button click event. I might be doing extra steps, but I know for sure this
works. I create a temporary file, stream the text ( probably your
Output.ToString() ) to this file, then open the file up and read the bytes
then using BinaryWrite to send the bytes to the browser.

You could probably just skip the temp file and convert your string to bytes.

string filename = "Name Of Report.csv";
byte [] bytes = Read file bytes.

Response.ClearHeaders();
Response.Clear();
Response.AddHeader( "Content-Disposition", "inline; filename=" +
filename );
Response.ContentType = "text/csv";
Response.BinaryWrite( bytes );
Response.End();

HTH,

bill

"Dorte" <Do***@discussions.microsoft.com> wrote in message
news:06**********************************@microsof t.com...
Hi,

I am using the code below to stream a CSV file with the response object.

Dim FileName As String = "Test.csv"
With Web.HttpContext.Current.Response

Web.HttpContext.Current.Response.AddHeader("conten t-disposition",
"attachment; filename=" & FileName)
.Charset = ""
.Write(Output.ToString()) ' Output is a StringBuilder object
with the content to write
.End()
End With

But when this code has been executed, a dialog pops up asking the user
whether to save or open the file. If the user clicks "Open", the dialog

pops
up again. After cliking "Open" in the second dialog, the file is opened by
Excel. If the user clicks "Save", the file is saved, and the dialog has

only
appeared once.
In the first dialog "Always ask before opening this type of file" is

grayed
out - in the second it is enabled, and checked.
Why does the dialog show up twice? Has it something to do with the browser
settings, or what am I doing wrong? I would appreciate any kind of help.

Thanks,
Dorte


Nov 18 '05 #5

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

Similar topics

5
by: Gord | last post by:
Hello, If you set the flag for an overwrite prompt using the 'Save' common dialog, how do you read the response when the user clicks the Yes or No in the 'overwrite' message box? Everything...
12
by: rockocubs | last post by:
Is there a way in Javascript to bring up dialog boxes for both opening and then also saving a file?
4
by: Max Dupenois | last post by:
I've seen numerous articles with similair (similar sp?) titles to this in my search.. unfortunately none of them seem to contain what i want, (or if they do i need someone to point out my stupidity...
3
by: Buddy Ackerman | last post by:
I'm trying to write files directly to the client so that it forces the client to open the Save As dialog box rather than display the file. On some occasions the files are very large (100MB+). On...
0
by: Thomas Gurath | last post by:
I have some code that reads a file from disk and inserts it into the http response. When the user clicks the file's title linkbutton, the File Download prompt appears twice if they select Open...
1
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
6
by: john | last post by:
The standard method to transmit a file from an aspx page to a browser is to stream the file to the response then end the response. The HTML code generated by the aspx page is discarded, and the...
17
by: Peter Duniho | last post by:
I searched using Google, on the web and in the newsgroups, and found nothing on this topic. Hopefully that means I just don't understand what I'm supposed to be doing here. :) The problem: ...
0
by: Jonathan | last post by:
Hi everyone, I'm having an issue with my Excel streaming. I run my procedure and if I "Save As" when the dialog opens and then open the file I generate, it's perfect. Also, if I choose "Open" when...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.