0
 string attachment = "attachment; filename=Myfile.csv";
 HttpContext.Current.Response.Clear();
 HttpContext.Current.Response.ClearHeaders();
 HttpContext.Current.Response.ClearContent();
 HttpContext.Current.Response.AddHeader("content-disposition", attachment);
 HttpContext.Current.Response.ContentType = "text/csv";
 HttpContext.Current.Response.AddHeader("Pragma", "public");

// My logic goes here to write file.

// Now I want to copy above file to another file.

 string filepath = Server.MapPath("~/ExportedFiles/") +"Newfile.csv";
 var ExcelFile = File.Create(filepath);
 ExcelFile.Close();
 HttpContext.Current.Response.TransmitFile(filepath);
 HttpContext.Current.Response.Flush();

The above code is not working, please suggest me. Thanks.

Rao
  • 71
  • 1
  • 9

2 Answers2

1

you need to create a virtual directory on your IIS and share that virtual directory directory. Your csv should reside in your virtual directory shared location. here is referenced article: http://www.codeproject.com/Tips/502741/A-solution-to-problem-Response-TransmitFile

amit dayama
  • 3,246
  • 2
  • 17
  • 28
0

use code bellow rather than: var ExcelFile = File.Create(filepath); WriteAllLines instruction in C# use to create file or change content file

File.WriteAllLines(filepath, data);
Jojo
  • 1
  • 1
  • Please add some description rather than just posting the answer, it will help others to avoid the problems in the future. – VPK Mar 16 '17 at 08:46