HTMLファイルのコンテンツの一部を置き換えると、String.Replaceが正しく機能しないようです。たとえば、String.Replaceは次のように置き換え</body></html>
られblah blah blah </body></html> html>
ます。2番目のHTML終了タグが適切に閉じられていないため、ユーザーがブラウザでページをレンダリングしたときに表示されることに注意してください。
なぜそれが意図したように機能しないのか誰かが知っていますか?
StreamReader sr = fi.OpenText;
String fileContents = sr.ReadToEnd();
sr.close();
fileContents = fileContents.Replace("<body>", "<body onload='jsFx();' />");
fileContents = fileContents.Replace("</body>","blah blah blah </body>");
StreamWriter sw = new StreamWriter(fi.OpenWrite());
sw.WriteLine(contents);
sw.close();