首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

.请教:System.IO 创建文件 有关问题

2012-01-14 
.请问:System.IO 创建文件 问题创建一个ascx文件把内容写到这个文件if(hiContent.Value!null&&hiContent.

.请问: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);
}

热点排行