我創建從一個List<>
這樣一個CSV文件:創建一個CSV文件,並通過FTP在MVC/C#上傳到服務器
public void ExportListToCSV()
{
StringWriter sw = new StringWriter();
sw.WriteLine("\"username\",firstname, lastname , email , course1 , course2 , course3 , course4 ");
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment;filename=OgrenciListesi.csv");
Response.ContentType = "text/csv";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1254");
Response.Charset = "windows-1254";
foreach (var line in Liste())
{
sw.WriteLine(string.Format("\"{0}\", {1} , {2} , {3} , {4} , {5} , {6} , {7} ",
line.KullaniciKodu,
line.Adi,
line.Soyadi,
line.Email,
line.Course1,
line.Course2,
line.Course3,
line.Course4
));
}
Response.Write(sw.ToString());
Response.End();
}
我想通過FTP在同一動作這個CSV發送到服務器(也許用相同的方法)。我如何處理這個CSV並通過FTP在C#中上傳到服務器?
首先將它保存到一個文件中,而不是發送給客戶端,然後使用FtpWebRequest將其上傳到FTP服務器。看看這個[如何:用FTP上傳文件](https://msdn.microsoft.com/en-us/library/ms229715(v = vs.110).aspx) –
您是否意味着保存到磁盤或記憶? (Diske kaydetmeden yollamak istiyorum da) – LacOniC
:-)在這種情況下,嘗試[WebClient.UploadData](https://msdn.microsoft.com/en-us/library/tdbbwh0a(v = vs.110).aspx)上傳一個流沒有保存到一個文件 –