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();
上述代碼無法正常工作,請給我建議。謝謝。如何在C#中編寫文件?
的可能的複製[最簡單的方法讀取和寫入文件(http://stackoverflow.com/questions/7569904/easiest-way-讀取和寫入文件) – Keale
請定義「不工作」 - 編譯錯誤,運行時錯誤,意外輸出?加上關於那個錯誤的任何細節。 –
沒有得到任何錯誤。但它不寫入Newfile.csv – Rao