문제

I made an application to make some changes to aspx files, but after that the problem with special characters were in browsers, I used this method to replace the run aspx files:

   File.WriteAllText(item.pathFile, File.ReadAllText(item.pathFile).Replace(item.OriginalContent, item.ChangedContent));

But after that all aspx pages are appearing with special characters problem in browsers

도움이 되었습니까?

해결책

Encoding enc = GetEncording(item.pathFile);
File.WriteAllText(item.pathFile, 
          File.ReadAllText(item.pathFile, enc).Replace(item.OriginalContent, 
          item.ChangedContent), 
        enc);

by using

public Encoding GetEncording(string filePath)
{
    Encoding enc = Encoding.Default;
    using (var r = new StreamReader(filePath, detectEncodingFromByteOrderMarks: true))
    {
        enc = r.CurrentEncoding;
    }
    return enc;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top