c# - Linq to CSV : Convert data to .CSV file and return file from an action without saving file on the server -


I am converting my data to a downloadable CSV file.

What I have done:

I did the same thing shown below:

  public fileResult GetReportCsvData (MyFilterModel model) {var data = _myService.GetMyData (ideal); Var fileName = String.Format ("{0} _ {1} _ {2: yyyy_MMM_d}", helpers.GetLogidInUser Name (), "Advertisement Report", Date Time Today) + ".csv"; Var outputFileDescription = new CsvFileDescription {separator = ',', firstline hous columnname = true}; Var cc = new csvContext (); Cc.write (data, "c: /" + filename, output file description); Return file ("c: /" + filename, System.Net.Mime.MediaTypeNames.Application.Octet, fileName); }   

and I can get my CSV file using the following jquery:

  exportCsv: function () {var data = this.getFilters ( ); Var url = '/ MyController / GetReportCsvData'; Var form = document.createElement ('form'); Form.action = url; Form.method = 'POST'; Form.style.display = 'none'; (Data in i) (if (data [i]! = "") {Var inputElement = document.createElement ('textarea'); InputElement.name = i; InputElement.value = data [i]; form.appendChild (inputElement) );}} Document.body.appendChild (form); form.submit ();}   

This works and I get the CSV file with the download prompt.

What do I need

With the current code I have to save the file to my server (c: / filename) and then return its file object.

I do not want to save it to my server.

How can you get it?

On "cc.write" you type disk, Output fileDescription is already a textstream, instead of saving it first on disk, and then reading it from disk with "file", just return textstream

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -