【发布时间】:2025-11-22 13:10:01
【问题描述】:
我试过this aproach没有任何成功
我正在使用的代码:
// File name
String filename = String.Format("{0:ddMMyyHHmm}", dtFileCreated);
String filePath = Path.Combine(Server.MapPath("App_Data"), filename + ".txt");
// Process
myObject pbs = new myObject();
pbs.GenerateFile();
// pbs.GeneratedFile is a StringBuilder object
// Save file
Encoding utf8WithoutBom = new UTF8Encoding(true);
TextWriter tw = new StreamWriter(filePath, false, utf8WithoutBom);
foreach (string s in pbs.GeneratedFile.ToArray())
tw.WriteLine(s);
tw.Close();
// Push Generated File into Client
Response.Clear();
Response.ContentType = "application/vnd.text";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + ".txt");
Response.TransmitFile(filePath);
Response.End();
结果:
无论如何都是writing the BOM,以及特殊字符(如Æ Ø Å) 不正确:-/
我卡住了!
我的目标是创建一个使用 UTF-8 作为编码和 8859-1 作为字符集的文件
这是很难完成还是我的日子不好过?
非常感谢所有帮助,谢谢!
【问题讨论】:
-
"a file using UTF-8 as Encoding and 8859-1 as CharSet" : encoding 和 charset 是一回事,所以你的要求没有意义...
标签: c# asp.net-3.5 text-files byte-order-mark