Solved

Problem when openning excel document. Two popups come up.

Posted on 2007-12-03
6
194 Views
Last Modified: 2013-12-16
The following code I have too explorers popup for saving excel files.

What am I missing.

protected void Page_Load(object sender, EventArgs e)
    {
        DataTable dt = (DataTable)Session["EXPORT_RESULT"];
        string filename = "export.csv";
        filename = string.Format("filename={0}", filename);
        Response.AppendHeader("content-disposition", filename);
        Response.ContentType = "application/vnd.ms-excel";
        Response.ContentEncoding = System.Text.Encoding.Default;

        // Envoyer les données (fichier CSV) au Browser
        Response.Write(GetCSVString(dt, false));
    }
0
Comment
Question by:mathieu_cupryk
  • 2
  • 2
  • 2
6 Comments
 
LVL 17

Accepted Solution

by:
Daniel Reynolds earned 500 total points
ID: 20400174
Can you write anything to an excel file? Try the following to just get a sample going and see if it will create the file for you. Once you know you are writing or saving the file, you can keep progressing on.
 
           Response.ContentType = "application/vnd.ms-excel";
            Response.AddHeader("Content-Disposition", "attachment; filename=c:\\myfile.xls");
            Response.Write("<HTML>\n");
            Response.Write("      <head runat='server'>\n");
            Response.Write("            <title>Excell_Output</title>\n");
            Response.Write("      </head>\n");
            Response.Write("      <body>\n");
            Response.Write("<table><tr><td>Howdy</td></tr></table");
            Response.Write("      </body>");
            Response.Write("</HTML>");
0
 

Author Comment

by:mathieu_cupryk
ID: 20401031
I am not sure what this will help me with. What do you mean? Once you know you are writing or saving the file, you can keep progressing on.

0
 
LVL 10

Expert Comment

by:digitalZo
ID: 20401156
Perhaps it's because it's getting called twice. Does the Excel grid on a new form? If so, what is the excel button click code? Can you post it?
0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 10

Expert Comment

by:digitalZo
ID: 20401158
A typo:

Is* the Excel grid on a new form?
0
 
LVL 17

Expert Comment

by:Daniel Reynolds
ID: 20404617
You said you were having a problem saving the excel file.
The code I displayed for you works to bring up the save/open dialog for an xls file.
In the process of debugging, I am just trying to make sure you eliminate each point of possible failure to eventually get the end results.
The first point of failure to eliminate is to get your syntax right with saving/writing a file to the response stream in the excel format.

So, if you do can do that, then you would next go to your routine where you read the data to save to your csv file and work thru that making sure there are no errors in it.
0
 

Author Closing Comment

by:mathieu_cupryk
ID: 31412455
This is a good solution and help me out. I used a button instead of a link.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question