public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string path = Server.MapPath("Test/News/2/2/1.txt");
Command.WriteAllText(path, "write is OK");
}
}
public class Command
{
public Command()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
/// <summary>
///
/// </summary>
/// <param name="path"></param>
/// <param name="content"></param>
public static void WriteAllText(string path, string content)
{
string path1 = SetPath(path);
Directory.CreateDirectory(path1);
File.WriteAllText(path, content, System.Text.Encoding.UTF8);
}
/// <summary>
/// c:\\cn\news\2012\1.txt
/// c:\\cn\news\2012 1.txt
/// </summary>
/// <returns></returns>
private static string SetPath(string path)
{
int aa = path.LastIndexOf("\\");
string pp1 = path.Substring(0, aa + 1);
return pp1;
}
}