Go homepage(回首页)
Upload pictures (上传图片)
Write articles (发文字帖)

The author:(作者)qq
published in(发表于) 2014/7/9 1:39:32
ASP.NET写文件

ASP.NET写文件

#region 写文件

///

/// 写文件

///

/// 文件内容

/// 文件名字

/// 文件路径

///

public bool WriteFile(string strContent, string strFileName, string strFilePath)

{

bool blnSuccess;

StreamWriter sw = null;

string strToPath = Path.GetFullPath(strFilePath);

//判断目录是不是存在

if (!Directory.Exists(strToPath))

{

Directory.CreateDirectory(strToPath);

}

Encoding ecdFileCode = Encoding.GetEncoding("gb2312");

// 写文件

try

{

sw = new StreamWriter(strToPath + "/" + strFileName, false, ecdFileCode);

sw.Write(strContent);

sw.Flush();

blnSuccess = true;

}

catch

{

blnSuccess = false;

throw;

}

finally

{

sw.Close();

}

return blnSuccess;

}

#endregion




If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)





QQ:154298438
QQ:417480759