stream Excel to browser- Framework 2.0

  • Thread starter Thread starter Rick
  • Start date Start date
R

Rick

I have a Framework 2.0 web site running on a Window 2003 server, We are
streaming an excel file(csv) into the browser for one of our customer
reports, When the excel browser window opens the data is in HTLM format, I
open the same file runnning a duplicate web site from my machine(XP) and the
data shows normally.

'Code that streams file to browser

Dim resp As HttpResponse
resp = Page.Response
resp.Clear()
resp.ContentType = "application/vnd.ms-excel"
resp.AppendHeader("Content-Disposition", "attachment;filename=" &
reportfilenamehere)
resp.WriteFile(reportfilenamehere)
resp.Flush()
resp.End()

Any Suggestion on how to solve this issue?

Thanks in Advance,
Rick
 
I think it depends on a version of the browser.
I recall a KB on Microsoft about bug if you try to stream over https. So
make sure you doing it over http.

Also try to make sure your reportrfilename has appropriate extension .xls or
..csv


George.
 
reports, When the excel browser window opens the data is in HTLM format

You mean that Excel file is opened inside the browser window (but not
in HTML format)

Try to delete ContentType and see what happen

resp.ContentType = "application/vnd.ms-excel"
 
Hello Rick,

From your post, my understanding on this issue is: you wonder why the csv
file is displayed in Excel application instead of web browser when you try
to stream the csv in a web application on Windows 2003 server. If I'm off
base, please feel free to let me know.

Where to open the office document in IE is determined by the configuration
of the client. The following KB explains how to configure IE to open Office
documents in the appropriate program (Office Program or Internet Explorer).
http://support.microsoft.com/kb/q162059/
Because the web application runs well in your Window XP system, my guess is
that the corresponding configuration differs in the two systems.

In order to ensure that the Office document is opened in IE, there are two
workarounds for your reference:
1. using OLEDB to query and display excel data.
Below is a KB article describes how to accomplish it in detail.
http://support.microsoft.com/kb/306572/en-us

2. using Office automation to automate Excel to save the csv as html
format, then embed the html into a page frame.
But this approach requires that your server is installed with Office system
and Office Primary Interop Assembly. To automate Microsoft Excel from
Visual C# .NET, please refer to the following articles:

How to automate Microsoft Excel from Microsoft Visual C# .NET
http://support.microsoft.com/kb/302084/en-us

INFO: Develop Microsoft Office solutions with Visual Studio .NET
http://support.microsoft.com/kb/311452/en-us

If you have any other concern or need anything else, please feel free to
let me know.

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
No, it's not that it is displayed in an excel application, when the excel
app opens in IE Browser,
the text is shows in HTML format, instead of the actual text that should
show, it looks like the webpage HTML is being thrown into the browser in
exel, instead of the actual file that should be shown, this works fine in
Framework 1.1 but not in 2.0:

THIS IS HOW IT DISPLAYS IN THE Browser:

<TABLE border="0" width="100%" cellpadding="0" cellspacing="0">
<TR>
<TD><TABLE border="0" cellpadding="0" cellspacing="0" width="100%"
class="TopHeader">
<TR>
<TD valign="top"><img id="_ctl0_imgLogo"
src="http://www-websitehere/images/logos/customer.gif" border="0" /></TD>
<TD valign="top" background="images/topmiddle.jpg" align="right"
width="100%">
<IMG src="images/is_single_pixel_gif.gif" height="1" width="1"></TD>
<TD valign="top" background="images/topright.jpg" align="right"><IMG
src="images/is_single_pixel_gif.gif" width="500" height="100%"></TD>
</TR>
</TABLE>

THIS IS HOW IT SHOULD DISPLAY:


Template Type: Post 2 Large (8 1/2 x 5 1/2)
Rule InternalClientID RuleType RuleDescription EffectiveDate
ExpirationDate RuleStatus Postcard 2 Back Postcard 2 Front RuleCardStock
RuleMemberNameFormat RuleProductionType RuleSpecialInstructions ShipToName
Shipping Method RuleNumber
Everest Postcard Everest Postcard R Everest Postcard Large ########
######## Active GLOBAL-P2B-EVERESTEVERPCB2POSTCARD2BACK-030507.EPS
GLOBAL-P2F-EVERESTEVERPCF1POSTCARD2FACE-030507.EPS 100# Dull Cover
Fname+Ml+Lname Non Union Aqueous Coat both sides cut to 8 1/2 x 4 1/4 if
under 250 pcs place stamp over indicia 239757
 
Hello Rick,

Sorry for my misunderstanding. But I am still not quite clear about the
follwing points:
1. as far as I know, csv file does not support containing images. But why
the following html image tag shows as the output of csv in the browser?
<img id="_ctl0_imgLogo"
src="http://www-websitehere/images/logos/customer.gif" border="0" />
2. According to your description, the html tags are directly shown in the
browser in .NET 2.0. Am I right? Is your browser showing the bare html?
3. In the section "THIS IS HOW IT SHOULD DISPLAY", it seems that the
newsgroup system split the long string and I am not able to view it
clearly. Is it in a form of table or a single string?

Would you mind sending a sample project that could reproduce the issue to
my mailbox ([email protected], remove 'online.'), so that I could
have a clearer picture of the issue? Many thanks for your time and I am
looking forward to your reply.

Have a nice day!

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hello Rick,

Thank you for the prompt reply. I have received your email. According to
the picture "ReportPage_ShowAsHtml.JPG", Excel is showing the html source
of a web page. Would you help to check what web page is that for? Is it the
page where you click on the download button? (But it is strange that I
cannot find the button's html tag according to the screen shot.) In the
meantime, can you access the csv file located on the server? Would you help
to open it directly on server and see whether the csv's content is correct?
Is it possible that the csv file on the server has been overwritten
unexpectedly?

In order to test whether a csv file could be shown correctly in the
browser, I did the following test on a Window 2003 Server system, with .NET
2.0, Visual Studio 2005, and Office 2003 Enterprise (SP2). I have attached
the complete test web project and the test csv file to this reply. (You
could download the attachment with Outlook Express or Windows Mail). The
test project worked as expected in my side.

In the test project, I created a simple VB.NET web application with Visual
Studio 2005. There is only on button <asp:Button ID="Button1"
runat="server" Onclick="Button1_Click" Text="Download" /> in the
Default.aspx page. In Button1_Click event handler, I paste your code there:
Dim resp As HttpResponse
Dim reportfilenamehere As String = "Book1.csv"
resp = Page.Response
resp.Clear()
resp.ContentType = "application/vnd.ms-excel"
resp.AppendHeader("Content-Disposition", "attachment;filename=" &
reportfilenamehere)
resp.WriteFile(reportfilenamehere)
resp.Flush()
resp.End()
Book1.csv is located in the same directory as Default.aspx, and it only
contains two lines of data:
1,1,1,1
2,2,2,2
When I run the project and clicks on the "download" button, the csv is
downloaded and shown correctly. I also tested to publish the web
application to another Windows 2003 server system, then visit the site, I
am still not able to reproduce the issue in my side. Would you please check
the points I mentioned in the beginning of the reply and let me know the
result? I am looking forward to your reply.

I understand that we didn't make much progress on this issue so far. It's
mainly because it's not reproducible in my side and yours and it is not
convenient to do the tests directly. Although troubleshooting such issues
in newsgroup might not be the best channel, I will try my best to help.

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hello Rick,

Thank you for the prompt reply. I have received your email. According to
the picture "ReportPage_ShowAsHtml.JPG", Excel is showing the html source
of a web page. Would you help to check what web page is that for? Is it the
page where you click on the download button? (But it is strange that I
cannot find the button's html tag according to the screen shot.) In the
meantime, can you access the csv file located on the server? Would you help
to open it directly on server and see whether the csv's content is correct?
Is it possible that the csv file on the server has been overwritten
unexpectedly?

In order to test whether a csv file could be shown correctly in the
browser, I did the following test on a Window 2003 Server system, with .NET
2.0, Visual Studio 2005, and Office 2003 Enterprise (SP2). I have attached
the complete test web project and the test csv file to this reply. (You
could download the attachment with Outlook Express or Windows Mail). The
test project worked as expected in my side.

In the test project, I created a simple VB.NET web application with Visual
Studio 2005. There is only on button <asp:Button ID="Button1"
runat="server" Onclick="Button1_Click" Text="Download" /> in the
Default.aspx page. In Button1_Click event handler, I paste your code there:
Dim resp As HttpResponse
Dim reportfilenamehere As String = "Book1.csv"
resp = Page.Response
resp.Clear()
resp.ContentType = "application/vnd.ms-excel"
resp.AppendHeader("Content-Disposition", "attachment;filename=" &
reportfilenamehere)
resp.WriteFile(reportfilenamehere)
resp.Flush()
resp.End()
Book1.csv is located in the same directory as Default.aspx, and it only
contains two lines of data:
1,1,1,1
2,2,2,2
When I run the project and clicks on the "download" button, the csv is
downloaded and shown correctly. I also tested to publish the web
application to another Windows 2003 server system, then visit the site, I
am still not able to reproduce the issue in my side. Would you please check
the points I mentioned in the beginning of the reply and let me know the
result? I am looking forward to your reply.

I understand that we didn't make much progress on this issue so far. It's
mainly because it's not reproducible in my side and yours and it is not
convenient to do the tests directly. Although troubleshooting such issues
in newsgroup might not be the best channel, I will try my best to help.

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top