none
Need to create CSV file on user's machine NOT on server RRS feed

  • Question

  • I have web application with MVC C#. When the user clicks a button Export-csv it creates CSV file on the server instead on his machine. Why?

    string connectionString =
                        ConfigurationManager.ConnectionStrings["SVRCS"].ConnectionString;


                    MySqlConnection conn = new MySqlConnection(connectionString);
                    MySqlCommand command = new MySqlCommand(str.ToString(), conn);
                    conn.Open();
                    MySqlDataReader rdr = command.ExecuteReader();

                    while (rdr.Read())
                    {
                        Pciserver pciserver = new Pciserver();
                        
                        sb.Append(rdr["ChangeID"].ToString() + strDelimitter);
                        sb.Append(rdr["Summary"].ToString() + strDelimitter);
                        sb.Append(rdr["Status"].ToString() + strDelimitter);
                        sb.Append(rdr["CoordinatorGroup"].ToString() + strDelimitter);
                        sb.Append(rdr["Class"].ToString() + strDelimitter);
                        sb.Append(rdr["ScheduledStartDate"].ToString() + strDelimitter);
                        sb.Append(rdr["ScheduledEndDate"].ToString() + strDelimitter);
                        sb.Append(rdr["Environment"].ToString() + strDelimitter);
                        sb.Append(rdr["ProductName"].ToString() + strDelimitter);
                        sb.Append(rdr["ChangeCoordinator"].ToString() + strDelimitter);
                        sb.Append(rdr["Urgency"].ToString() + strDelimitter);
                        sb.Append(rdr["RiskLevel"].ToString() + strDelimitter);
                        sb.Append("\r\n");
                       
                    }
                    ViewBag.SaveCsv = "CSV File in directory c:\\temp\\ReportChange.csv";
                 
                    StreamWriter file = new StreamWriter(@"c:\temp\ReportChange.csv");
                    
                    file.WriteLine(sb.ToString());
                    file.Close();

    • Moved by CoolDadTx Thursday, October 5, 2017 3:45 PM ASP.NET related
    Thursday, October 5, 2017 2:50 PM

All replies