Solved

Problem when openning excel document. Two popups come up.

Posted on 2007-12-03
6
193 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

816 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

8 Experts available now in Live!

Get 1:1 Help Now