Error and double open dialog when downloading Excel file from ASP.NET.

G

Guest

I've got two problems. First, when this code works, I get a "Open/Save/Cancel" dialog and if I click "Open", I get the same dialog again and then IE opens Excel. So what am I doing wrong to get the double dialog? Also, I occasionally get a "Server Application Unavailable" error message (as an HTML page) instead of the download. When I get the error, two log files are generated into my web server's "TEMP" directory, both of which contain

=== Verbose logging started: 3/26/2004 16:59:49 Build type: SHIP UNICODE 2.00.2600.1183 Calling process: E:\Program Files\Microsoft Office\Office10\EXCEL.EXE ==
MSI (c) (74:14): Resetting cached policy value
MSI (c) (74:14): Machine policy value 'Debug' is
MSI (c) (74:14): ******* RunEngine
******* Product: {90280409-6000-11D3-8CFE-0050048383C9
******* Action:
******* CommandLine: *********
MSI (c) (74:14): Client-side and UI is none or basic: Running entire install on the server
MSI (c) (74:14): Grabbed execution mutex
MSI (c) (74:14): Failed to connect to server. Error: 0x8007000

MSI (c) (74:14): Failed to connect to server
MSI (c) (74:14): MainEngineThread is returning 160
=== Verbose logging stopped: 3/26/2004 16:59:49 ==


In case I'm doing something wrong, the current code is

System.IO.FileInfo fi = new System.IO.FileInfo(sFileName)
String sFileLength = fi.Length.ToString()
Response.ClearHeaders()
Response.Clear()
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Response.AddHeader("Content-Disposition", "attachment;filename=" + sNameOnly)
Response.AddHeader("Content-Length", sFileLength)
Response.WriteFile(sFileName)

Thanks

Lowell
 
A

Alvin Bruney [MVP]

You need a response.end to terminate and don't forget it's a good idea to
null out your objects when you are done.

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Lowell said:
I've got two problems. First, when this code works, I get a
"Open/Save/Cancel" dialog and if I click "Open", I get the same dialog again
and then IE opens Excel. So what am I doing wrong to get the double dialog?
Also, I occasionally get a "Server Application Unavailable" error message
(as an HTML page) instead of the download. When I get the error, two log
files are generated into my web server's "TEMP" directory, both of which
contain:
=== Verbose logging started: 3/26/2004 16:59:49 Build type: SHIP UNICODE
2.00.2600.1183 Calling process: E:\Program Files\Microsoft
Office\Office10\EXCEL.EXE ===
 
S

Scott

Lowell,
I already have a Response.End() and it's still broken; if it works for you, please post.

Thanks.

Alvin Bruney said:
You need a response.end to terminate and don't forget it's a good idea to
null out your objects when you are done.

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Lowell said:
I've got two problems. First, when this code works, I get a
"Open/Save/Cancel" dialog and if I click "Open", I get the same dialog again
and then IE opens Excel. So what am I doing wrong to get the double dialog?
Also, I occasionally get a "Server Application Unavailable" error message
(as an HTML page) instead of the download. When I get the error, two log
files are generated into my web server's "TEMP" directory, both of which
contain:
=== Verbose logging started: 3/26/2004 16:59:49 Build type: SHIP UNICODE
2.00.2600.1183 Calling process: E:\Program Files\Microsoft
Office\Office10\EXCEL.EXE ===
MSI (c) (74:14): Resetting cached policy values
MSI (c) (74:14): Machine policy value 'Debug' is 0
MSI (c) (74:14): ******* RunEngine:
******* Product: {90280409-6000-11D3-8CFE-0050048383C9}
******* Action:
******* CommandLine: **********
MSI (c) (74:14): Client-side and UI is none or basic: Running entire install on the server.
MSI (c) (74:14): Grabbed execution mutex.
MSI (c) (74:14): Failed to connect to server. Error: 0x80070005

MSI (c) (74:14): Failed to connect to server.
MSI (c) (74:14): MainEngineThread is returning 1601
=== Verbose logging stopped: 3/26/2004 16:59:49 ===



In case I'm doing something wrong, the current code is:

System.IO.FileInfo fi = new System.IO.FileInfo(sFileName);
String sFileLength = fi.Length.ToString();
Response.ClearHeaders();
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
Response.AddHeader("Content-Disposition", "attachment;filename=" + sNameOnly);
Response.AddHeader("Content-Length", sFileLength);
Response.WriteFile(sFileName);

Thanks,

Lowell
 
M

[MSFT]

Hi Lowell,

I tried your code and I haven't been able to reproduce the problem. If you
open the excel file in IE like:

Response.ClearHeaders();
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";

'Response.AddHeader("Content-Disposition", "attachment;filename=" +
sNameOnly);
'Response.AddHeader("Content-Length", sFileLength);

Response.WriteFile(sFileName);

Will this work without errors?

addtionally, if you pass a csv or txt file instead or .xls. will it also
generate the error?

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
G

Guest

Well, the response.end() didn't make any difference

As far as "nulling out objects" goes, in the code that generates the Excel spreadsheet, when I'm closing things down, I include calls to the "System.Runtime.InteropServices.Marshal.ReleaseComObject()" method on a lot of the objects--especially the main ones like the "ExcelApp", the workbooks and sheets. (I don't do it for some of the intermediate, temporarily-created objects like ranges and charts, should I?

Thanks

Lowel
----- Alvin Bruney [MVP] wrote: ----

You need a response.end to terminate and don't forget it's a good idea t
null out your objects when you are done

--
Regards
Alvin Bruney [ASP.NET MVP
Got tidbits? Get it here..
http://tinyurl.com/3he3
Lowell said:
I've got two problems. First, when this code works, I get
"Open/Save/Cancel" dialog and if I click "Open", I get the same dialog agai
and then IE opens Excel. So what am I doing wrong to get the double dialog
Also, I occasionally get a "Server Application Unavailable" error messag
(as an HTML page) instead of the download. When I get the error, two lo
files are generated into my web server's "TEMP" directory, both of whic
contain2.00.2600.1183 Calling process: E:\Program Files\Microsof
Office\Office10\EXCEL.EXE ==
 
G

Guest

Hi Luke

I don't see any difference between your code and my original

I tried changing the file to a text file and the "ContentType" to "text/plain". Now, it doesn't seem to generate the error message, but I still get the double open dialog box (after which, the correct file gets downloaded and displayed in notepad.

Note, the error message seemed to be generated most reliably the *first* time after a "Build/Rebuild Solution" in VS2003 followed by Restarting the web server. Then, the second time, I would get the Excel spreadsheet to download

Thanks

Lowel

----- [MSFT] wrote: ----

Hi Lowell

I tried your code and I haven't been able to reproduce the problem. If you
open the excel file in IE like

Response.ClearHeaders()
Response.Clear()
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""

'Response.AddHeader("Content-Disposition", "attachment;filename=" +
sNameOnly)
'Response.AddHeader("Content-Length", sFileLength)

Response.WriteFile(sFileName)

Will this work without errors

addtionally, if you pass a csv or txt file instead or .xls. will it also
generate the error

Luk
Microsoft Online Suppor

Get Secure! www.microsoft.com/securit
(This posting is provided "AS IS", with no warranties, and confers no
rights.
 
M

[MSFT]

Hi Lowell,

Did the problem only occur on an particular client computer? Normally, the
double Open dialog problem should be related to the client environment. You
may try more other clients to see if it will make difference. Additionally,
check if it is realted to IE and MS Excel version.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Scott

I have the same problem; I'm running XP/Pro (IE6) and Excel 2002 (same problem with Excel 2000 on
Win2k).

Scott
 
G

Guest

Well, it looks like I've "fixed" both problems. (Although I'd still like to be able to make the other way work.) I changed my code to the following

// Generate Excel file
...
// Send Exce
sNameOnly = sFileName.Substring(sWorkingPath.Length + 1)
Response.Redirect ( sURL + "/" + sNameOnly, true )

I'm able to do this because I'm generating the file in a subdirectory of the main web server directory. It's still a second-best solution because it brings up the spreadsheet right in the browser, whereas the other method (when it worked) fired up a new window running Excel

Thanks

Lowel

----- Lowell wrote: ----

I've had the same problem with multiple clients (and servers--at least with Excel files). Right now I'm unable to test with anything other than my development box which has IE version 6.0.2800.1106 with updates SP1 and, I believe, all the latest updates

I'm running Office XP which might not be totally up to date. This is pretty much going to be my customer's environment

Thanks

Lowell
 
S

Scott

The other method allows the user to a "nice" name to save the file with; I thought about doing this
this kind of redirection to a separate page with an extension -- but I think the attachment method
nicer for the user (even if they have to click open twice).

I did get a report that a user with a ie 5.? browser doesn't have this problem; I'm going to try
and find out what the exact version they have. I have WinXP and Win2k (both with IE6) and the
problem persists (though I'm even more convinced it's problem with IE). Maybe the thing for me to do
is put a bit of code together that replicates this and post that.

Scott


Lowell said:
Well, it looks like I've "fixed" both problems. (Although I'd still like to be able to make the
other way work.) I changed my code to the following:
// Generate Excel file.
...
// Send Excel
sNameOnly = sFileName.Substring(sWorkingPath.Length + 1);
Response.Redirect ( sURL + "/" + sNameOnly, true );

I'm able to do this because I'm generating the file in a subdirectory of the main web server
directory. It's still a second-best solution because it brings up the spreadsheet right in the
browser, whereas the other method (when it worked) fired up a new window running Excel.
Thanks,

Lowell

----- Lowell wrote: -----

I've had the same problem with multiple clients (and servers--at least with Excel files).
Right now I'm unable to test with anything other than my development box which has IE version
6.0.2800.1106 with updates SP1 and, I believe, all the latest updates.
 
S

Scott

Here's a bit of sample code that always generates a double open dialog box. The only interesting
thing is that the first open dialog box has the "Always ask before open this type of file" is
greyed; on the second dialog box it's not greyed. If you click open, then open on the second dialog
box Excel will start with these bits.

Does anyone have any ideas?


<%@ Page language="c#" AutoEventWireup="false" %>
<script language="C#" runat="server">
public void Btn1_Click(object sender, System.EventArgs e)
{
string content = "Hello";
Response.Clear();
Response.ClearHeaders();
Response.Charset = "";
Response.ContentType = "application/csv";
Response.AddHeader("Content-Disposition", "attachment; filename=HelloWorld.csv");
Response.AddHeader("Content-Length", content.Length.ToString());
Response.Write(content);
Response.Flush();
Response.End();
}
</script>
<html>
<body>
<form id="Form1" method="post" runat="server">
<asp:Button id="Btn1" runat="server" Text="Button" onclick="Btn1_Click"></asp:Button>
</form>
</body>
</html>
 
G

Guest

I'm getting the same thing

Lowel

----- Scott wrote: ----


Here's a bit of sample code that always generates a double open dialog box. The only interestin
thing is that the first open dialog box has the "Always ask before open this type of file" i
greyed; on the second dialog box it's not greyed. If you click open, then open on the second dialo
box Excel will start with these bits

Does anyone have any ideas


<%@ Page language="c#" AutoEventWireup="false" %><script language="C#" runat="server"
public void Btn1_Click(object sender, System.EventArgs e

string content = "Hello"
Response.Clear()
Response.ClearHeaders()
Response.Charset = ""
Response.ContentType = "application/csv"
Response.AddHeader("Content-Disposition", "attachment; filename=HelloWorld.csv")
Response.AddHeader("Content-Length", content.Length.ToString())
Response.Write(content)
Response.Flush()
Response.End()

</script><html><body><form id="Form1" method="post" runat="server"><asp:Button id="Btn1" runat="server" Text="Button" onclick="Btn1_Click"></asp:Button></form></body></html
 
M

[MSFT]

Hi Lowell,

I tried your code but I haven't reproduced the problem on my side.
(currently I am working with IE 6.0 and Excel 2003) I think you may open
the client's registry and check follow entries:

HKEY_CLASSES_ROOT\MIME\Database\Content Type\application\Application
Name\Extension

HKEY_LOCAL_MACHINE\Software\Microsoft\Internet
Explorer\Plugins\Extension\File Extension

Check if they has been set to .xls

For your current work around, you may refer to following sample if the
Excel file has to be placed in other folders:

HOWTO: Use the ADODB.Stream Object to Send Binary Files to the Browser
through ASP
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q276488

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
M

[MSFT]

Hi Lowell

From your description, the registry is correct and we don't need to add
some entries.

With further research, I found an KB article may address this issue:

Internet Explorer Prompts the User with Two Open or Save Dialog Boxes
http://support.microsoft.com/?id=238588

You may take a look.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
M

[MSFT]

Hi Lowell,

My IE version is 6.0.3790.0 and I haven't found same problem with your
code> I suggest you try to upgrade one client from following links:

http://www.microsoft.com/windows/ie/default.asp
http://windowsupdate.microsoft.com

To see if it will help.

Additionally, if you add a direct link to the XLS file on a web page like:

<a href =some.xls>Click</a>

Will this also generate two dialog?

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top