Solved

Problem when openning excel document. Two popups come up.

Posted on 2007-12-03
6
192 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:
xDJR1875 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 10

Expert Comment

by:digitalZo
ID: 20401158
A typo:

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

Expert Comment

by:xDJR1875
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now