将文本重写为文件 [英] reWrite text to file
本文介绍了将文本重写为文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我用这段代码在文件中写一个字符串(strcontent)
string filePath = Server.MapPath( Emailtesttemplate.html);
string writeText = StrContent;
StreamWriter sw = File.AppendText(filePath);
sw.Write(writeText);
sw.Close();
Response.Write( < script>);
Response.Write( window.open('Emailtesttemplate.html','_ blank')跨度>);
Response.Write( < / script>);
此代码将文本添加到文件末尾!但我需要重写文件...
解决方案
使用WriteAllText()方法。只需确保您具有覆盖文本文件的相应权限,否则可能会拒绝覆盖。
System.IO.File.WriteAllText ( @ D:\ path.txt,contents);
Hi
I use this code to write a string in file (strcontent)
string filePath = Server.MapPath("Emailtesttemplate.html");
string writeText = StrContent;
StreamWriter sw = File.AppendText(filePath);
sw.Write(writeText);
sw.Close();
Response.Write("<script>");
Response.Write("window.open('Emailtesttemplate.html','_blank')");
Response.Write("</script>");
this code add text to end of file ! but I need to reWrite file ...
解决方案
Use the WriteAllText() method. Just make sure you have the appropriate privileges to overwrite the textfile otherwise the overwrite may be declined.
System.IO.File.WriteAllText (@"D:\path.txt", contents);
这篇关于将文本重写为文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文