public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; System.Collections.Specialized.NameValueCollection parameters = context.Request.Form; string moduleName = parameters["module"]; string requestFeedback = ""; switch (moduleName) { case "ExportToExcel": EgisWeb.ExportHelper objExportCSVHelper = new EgisWeb.ExportHelper(); objExportCSVHelper.CSV2Excel(parameters["csvdata"].ToString(), HttpContext.Current, parameters["title"].ToString()); break; } if (moduleName != "ExportToExcel") context.Response.Write(requestFeedback); } public void CSV2Excel(string strCSV, HttpContext current, string strTitle) { current.Response.Clear(); strCSV = removeUniCodeSequenceCharacters(strCSV); strCSV = System.Text.RegularExpressions.Regex.Unescape(strCSV); current.Response.AddHeader("content-disposition", "attachment;filename=" + strTitle +"_"+DateTime.Now.ToString("ddmmyyyyHHMMSS") + ".csv"); current.Response.Charset = ""; current.Response.ContentType = "application/octet-stream"; current.Response.Write(strCSV); current.Response.End(); } private string removeUniCodeSequenceCharacters(string strWithEscapeSequence) { string strUse = ""; strUse = strWithEscapeSequence.Replace("%20", " "); strUse = strUse.Replace("%2C", ","); strUse = strUse.Replace("%27", "'"); strUse = strUse.Replace("%22", "\""); strUse = strUse.Replace("%3F", "?"); strUse = strUse.Replace("%0A", "\n"); strUse = strUse.Replace("%28", "("); strUse = strUse.Replace("%29", ")"); strUse = strUse.Replace("%26", "&"); strUse = strUse.Replace("%23", "#"); strUse = strUse.Replace("%3A", ":"); strUse = strUse.Replace("%21", "!"); strUse = strUse.Replace("%2D", "-"); strUse = strUse.Replace("%3B", ";"); strUse = strUse.Replace("%2A", "*"); strUse = strUse.Replace("%2B", "+"); strUse = strUse.Replace("%2E", "."); strUse = strUse.Replace("%3C", "<"); strUse = strUse.Replace("%3D", "="); strUse = strUse.Replace("%3E", ">"); strUse = strUse.Replace("%40", "@"); return strUse; }
Solved! Go to Solution.
So user can just download the data to csv format and not just show the string data on the screen then have to copy and paste to save to csv format.
Hi May,
I have not studies the codes on the example you provided(Edit fiddle - JSFiddle). In addition, users still need to copy and paste and save to csv format in my application. For your requirement (users just download the data to csv format), I am still working on it. Hopefully you could let me know after you figured it out.
Thanks,
Hank
Sure. I will let you know
Chang-Heng and May Jeff,
Marks solution is a server side code that handles the csv response format.
Attached I have the CSVHandler.ashx code that you can add to your web server.
The steps are simple
grid.exportGrid("csv", function (str) { ioIframe.create('exportFrame', '', ''); ioIframe._currentDfd = null; ioIframe.send({ url: "/HttpHandlers/CSVHandler.ashx", content: {data: str, filename: 'MyExport.csv'} }); });
Notice the url is /HttpHandlers/CSVHandler.ashx
the content contains your csv str and the desired output file name for the download.