Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...Excel is replacing webpage on click of download to excelExcel is replacing webpage on click of download to excel
Previous
 
Next
New Post
5/8/2009 12:25 AM
 

Hi All,

 

i am working on a requirement where excel has to be generated on click of a button.

below is the code which will be executed on button click.

 strExcel contains the whole data in HTML layout

   Response.Clear()
            Response.AddHeader("content-disposition", "filename=Forecast.xls")
            Response.Charset = ""
            Response.Cache.SetCacheability(HttpCacheability.NoCache)
            Response.ContentType = "application/vnd.xls"
            Response.Write(strExcel)
            Response.End()
           
           
<asp:UpdatePanel>
  <ContentTemplate>
    <asp:Button ID="btnDownload" runat="server" Text="Download to XLS" Width="150px" />
  </ContentTemplate>
  <Triggers>
      <asp:AsyncPostBackTrigger ControlID="btnViewForeCast" EventName="Click" />
       <asp:PostBackTrigger ControlID="btnDownload" />
  </Triggers>
 

the issue is after user clicks on download to excel, the excel is replacing the webpage. it is supposed to open in excel.

however this issue is coming up in systems which have MS Office 2003 , in systems with Office 2007 this is getting opened in  excel.

please suggest me any approach to resolve this issue.

Thanks in Advance :)

 

 
New Post
5/8/2009 4:45 PM
 

The issue isn't really with your code.  It's with the browser and Microsoft Office integrations with that browser.

I have a script that also outputs to Excel.  When using IE6 and Office 2000, it opens the file within the browser window.  On the same machine, when using FireFox, it prompts me to open/save and opens a separate instance of Excel.  On a different machine (IE7 and Office 2007), it warns me about the file but opens a new instance of Excel 2007.

I think what you'd need to do would be to actually write the XLS file to the server and then provide a link to the file which forces it to download.

 
New Post
5/15/2009 10:27 AM
 

Use Response.BinaryWrite(buffer in byte[]); or Response.WriteFile("file");

It'll always prompt dialog box to user than ask user what to do? either open directly or save to disk.

And for " Response.BinaryWrite(buffer in byte[]);" this you ahve to pass file as a byte array... so keep in mind ...

And also add this [see bold text]

Response.AddHeader("content-disposition", "attachment; filename=JWordTestFile.xls");

 
Previous
 
Next
HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...Excel is replacing webpage on click of download to excelExcel is replacing webpage on click of download to excel


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out