473,216 Members | 1,381 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,216 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 3633
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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.