string filename = DateTime.Today.ToString()+"txt";
string filepath = @"d:\" ;
string path = Path.Combine(filepath,filename);
StreamWriter file;
if (!File.Exists(path))
{
file = File.CreateText(path);
file.Close();
}
异常: 文件路径格式不正确。看了代码各位大侠应该明白我的意思了。不多说了,大侠们小小的出下手就够了。
string filepath = @"d:\" ;
string path = Path.Combine(filepath,filename);
StreamWriter file;
if (!File.Exists(path))
{
file = File.CreateText(path);
file.Close();
}
异常: 文件路径格式不正确。看了代码各位大侠应该明白我的意思了。不多说了,大侠们小小的出下手就够了。
改成string filename = DateTime.Today.ToString("yyyyMMdd")+".txt"; 试试
不用Path.Combine
这里应该是()+".txt";
string path = Path.Combine(filepath,filename);
StreamWriter file;
if (!File.Exists(path))
{
file = File.CreateText(path);
file.Close();
} file = File.CreateText(path);
换成:
path = HttpContext.Current.Server.MapPath("~" + path);
file = File.CreateText(path);