.请问:System.IO 创建文件 问题
创建一个ascx文件
把内容写到这个文件
if (hiContent.Value != null && hiContent.Value != " ")
{
Response.Write(hiContent.Value);
StringWriter sw = new StringWriter();
sw = File.Create( "d:\\aaaa.ascx ") as StreamWriter;
string sContent = hiContent.Value;
sw.Write(sContent);
}
这个出现
CS0039: 无法通过内置转换将类型“System.IO.FileStream”转换为“System.IO.StreamWriter”
请问正确写法怎么写?
[解决办法]
StringWriter sw = new StringWriter(File.Create( "d:\\aaaa.ascx "));
[解决办法]
用StreamWriter比较方便
[解决办法]
string filename = "d:\\aaaa.ascx ";
if (!File.Exists(filename))
{
File.WriteAllText(filename, hiContent.Value);
}
else
{
string oldTEXT = File.ReadAllText(filename);
File.WriteAllText(filename, hiContent.Value);
}