将所有aspx文件从本地编码切换到utf-8

时间:2022-02-26 11:10:53

how can I save all files in a directory using utf-8?

如何使用utf-8保存目录中的所有文件?

There is a need to change the default file encoding in IIS to display all foreign characters correct. The problem is: all old files are saved in (different/random) encodings.

需要在IIS中更改默认文件编码以正确显示所有外来字符。问题是:所有旧文件都保存在(不同/随机)编码中。

Is there a way to open (in current) and save all those files safely to UTF-8?

有没有办法打开(当前)并将所有这些文件安全地保存到UTF-8?

2 个解决方案

#1


If the files are text files then you can use the overloaded System.IO.File.WriteAllText() method and pass the UTF-8 encoding type. That should do the trick

如果文件是文本文件,那么您可以使用重载的System.IO.File.WriteAllText()方法并传递UTF-8编码类型。这应该够了吧

#2


If you are using Visual Studio 2005 or 2008, you can change the encoding a file is saved with using File -> Advanced Save Options. You'll need to potentially do that for each file (though you can probably get away with doing it only to those files in which you have internationalized content).

如果您使用的是Visual Studio 2005或2008,则可以使用“文件” - >“高级保存选项”更改保存文件的编码。您可能需要为每个文件执行此操作(尽管您可能只对那些具有国际化内容的文件执行此操作)。

That said - be sure that when you render HTML to the user's browser that you are setting the encoding type with a meta tag in the head. The specific tag will be:

也就是说 - 确保当您向用户的浏览器呈现HTML时,您正在设置头部带有元标记的编码类型。具体标签将是:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 

#1


If the files are text files then you can use the overloaded System.IO.File.WriteAllText() method and pass the UTF-8 encoding type. That should do the trick

如果文件是文本文件,那么您可以使用重载的System.IO.File.WriteAllText()方法并传递UTF-8编码类型。这应该够了吧

#2


If you are using Visual Studio 2005 or 2008, you can change the encoding a file is saved with using File -> Advanced Save Options. You'll need to potentially do that for each file (though you can probably get away with doing it only to those files in which you have internationalized content).

如果您使用的是Visual Studio 2005或2008,则可以使用“文件” - >“高级保存选项”更改保存文件的编码。您可能需要为每个文件执行此操作(尽管您可能只对那些具有国际化内容的文件执行此操作)。

That said - be sure that when you render HTML to the user's browser that you are setting the encoding type with a meta tag in the head. The specific tag will be:

也就是说 - 确保当您向用户的浏览器呈现HTML时,您正在设置头部带有元标记的编码类型。具体标签将是:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>