.net - C# Export to CSV problems -


i using method accepts datatable , transform csv. problem is, (1) when try call method, succeeding process/commands never executed. (2) list box contents calling form cleared out after calling method. can me out on this? have included method below reference.

public void datatabletocsv(string filename, datatable dt) {     response.clear();     response.addheader("content-disposition", string.format("attachment;filename={0}.csv", filename + datetime.now.tostring().replace(" ", "").replace(":", "").replace(" ", "").replace("/", "")));     response.charset = "";     response.contenttype = "application/vnd.csv";     system.io.stringwriter swriter;     system.text.stringbuilder sb = new system.text.stringbuilder();      swriter = new system.io.stringwriter(sb);     string str;     (int k = 0; k <= (dt.columns.count - 1); k++)     {         swriter.write(dt.columns[k].columnname + ",");     }      swriter.writeline(",");     (int = 0; <= (dt.rows.count - 1); i++)     {         (int j = 0; j <= (dt.columns.count - 1); j++)         {             str = (dt.rows[i][j].tostring().replace(",", ""));             if (str == "&nbsp;")                 str = "";              str = (str + ",");             swriter.write(str);         }         swriter.writeline();     }     swriter.close();     response.write(sb.tostring());     response.end(); } 

regarding (1) - response.end() throws threadabortexception internally, terminates normal page life-cycle , 'jumps ahead' endrequest event. following call datatabletocsv() not called.

hope helps..


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -