English 中文(简体)
如何在纽顿被点击时为选择目的地提供浏览窗口
原标题:How to make a browse window for selecting destination when button is clicked

I have a simple button for exporting a database table from MySQL to excel file. So far its destination is hardcoded to C:/ drive. When you press the Export button you get excel file automatically exported to C: without the user able to see it. Here is the code:

//button for Exporting to Excel (.xls)
    //hardcoded destination to C:/
    protected void Button2_Click(object sender, EventArgs e)
    {
        try
        {
            string connectionString = "server=localhost; UserId=root; database=dbcss; ";
            MySqlConnection con = new MySqlConnection(connectionString);

            con.Open();
            string getProject = ddlProjectID.SelectedValue; //get the already selected project from the dropdown menu

            //create sql command object
            string cmdText = "SELECT  activity_id ,  activity_name ,  wbs_no ,  activity_status ,  wbs_name ,  sequence ,  pad ,  project_id ,  start_date ,  finish_date  INTO OUTFILE  C://TASK.xls  FROM management WHERE project_id =  " + getProject + " ;";

            MySqlCommand cmd = new MySqlCommand(cmdText, con);

            cmd.ExecuteNonQuery();
            con.Close();

        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }

    }

我怎么能做一个窗户,让你们能够浏览你们的c子和选择目的地?

Any help will be appreciated Thanks ;)

问题回答

You have to change your response header and content type and send back a file to the browser:

引证:

劳动合同向Excel提出质询。 信息网网站

一个点击伙伴关系。 NET Export button control for Excel/CSV file





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签