asp.net读写文件与建立目录简单函数
//写入文件 using (StreamWriter sw = new StreamWriter(filePath, false)) { sw.Write(xmlSTR); sw.Dispose(); } //读取文件内容 public static string ReadHtml(string Path) { string result = string.Empty; if (File.Exists(Path)) { try { usi
//写入文件
using (StreamWriter sw = new StreamWriter(filePath, false))
{
sw.Write(xmlSTR);
sw.Dispose();
}
//读取文件内容
public static string ReadHtml(string Path)
{
string result = string.Empty;
if (File.Exists(Path))
{
try
{
using (StreamReader sr = new StreamReader(Path))
{
result = sr.ReadToEnd();
}
}
catch
{ }
}
else
{
result = "模板不存在!";
}
return result;
}
//建立目录
public static void CreateDirectory(string Path)
{
if (!Directory.Exists(Path))
Directory.CreateDirectory(Path);
}
using (StreamWriter sw = new StreamWriter(filePath, false))
{
sw.Write(xmlSTR);
sw.Dispose();
}
//读取文件内容
public static string ReadHtml(string Path)
{
string result = string.Empty;
if (File.Exists(Path))
{
try
{
using (StreamReader sr = new StreamReader(Path))
{
result = sr.ReadToEnd();
}
}
catch
{ }
}
else
{
result = "模板不存在!";
}
return result;
}
//建立目录
public static void CreateDirectory(string Path)
{
if (!Directory.Exists(Path))
Directory.CreateDirectory(Path);
}
- 上一篇:作为.NET程序员的你应该知道些什么
- 下一篇:asp.net实现图片防盗链
精彩图集
精彩文章

