简单的写是这个样子的System.IO.StreamWriter stmPage = null;Directory.CreateDirectory("yourfolderpath");m_sPage = "youfilename";
if (!File.Exists(m_sPage))
{
try
{
stmPage = new StreamWriter(m_sPage,true);
if (stmPage != null)
{
stmPage.WriteLine("yourfilecontents");
stmPage.Close();
stmPage = null;
}
}
catch(System.Exception e)
{
}
}
if (!File.Exists(m_sPage))
{
try
{
stmPage = new StreamWriter(m_sPage,true);
if (stmPage != null)
{
stmPage.WriteLine("yourfilecontents");
stmPage.Close();
stmPage = null;
}
}
catch(System.Exception e)
{
}
}
if(Directory.Exists(path)==false) {//判断目录是否存在
//创建目录
Directory.CreateDirectory(path);
}
if(!Directory.Exists(sPath))
Directory.CreateDirectory(sPath);