我是新手,问个关于创建文件夹的问题...d
DirectoryInfo di = new DirectoryInfo( "E:// "+username.Text);
if (di.Exists == false)
di.Create();
DirectoryInfo dis = di.CreateSubdirectory( "data ");
这里创建文件的只是绝对路径,但是我不想用绝对路径,想用相对路径,想请问一下,应该怎么写?把文件创建在该软件的根目录下。
------解决方案--------------------DirectoryInfo di = new DirectoryInfo(Application.StartupPath+ "\\ "+username.Text);
if (di.Exists == false)
di.Create();
DirectoryInfo dis = di.CreateSubdirectory( "data ");
立即成为编程经验丰富的程序员不是梦,详见:http://www.psec.net.cn
------解决方案--------------------string FolderPath = Server.MapPath( "/LoginLog/ " + System.DateTime.Now.ToString( "yyyy-MM "));
if (!Directory.Exists(FolderPath))
{
//文件夹不存在则创建
Directory.CreateDirectory(FolderPath);
//写入日志
string FilePath = Server.MapPath( "/LoginLog/ " + DateTime.Now.ToString( "yyyy-MM ") + "/ " + DateTime.Now.ToString( "yyyy-MM-dd "));
if (!Directory.Exists(FilePath))
{
//如果文件存在则写入日志
using (StreamWriter writer = File.AppendText(FilePath + ".txt "))
{
writer.WriteLine( "[登录成功!][用户IP]: " + ip + "; [登录时间]: " + DateTime.Now);
writer.Flush();
writer.Close();
}
}
else
{
//如果文件不存在当前目录下创建一个文本文件
StreamWriter writer = new StreamWriter(FilePath + ".txt ");
writer.WriteLine( "[登录成功!][用户IP]: " + ip + "; [登录时间]: " + DateTime.Now);
writer.Flush();
writer.Close();
}
}
else
{
//文件夹存在则写入日志
string FilePath = Server.MapPath( "/LoginLog/ " + DateTime.Now.ToString( "yyyy-MM ") + "/ " + DateTime.Now.ToString( "yyyy-MM-dd "));
if (!Directory.Exists(FilePath))
{
//如果文件存在则写入日志
using (StreamWriter writer = File.AppendText(FilePath + ".txt "))
{
writer.WriteLine( "[登录成功!][用户IP]: " + ip + "; [登录时间]: " + DateTime.Now);
writer.Flush();
writer.Close();
}
}
else
{
//如果文件不存在当前目录下创建一个文本文件
StreamWriter writer = new StreamWriter(FilePath + ".txt ");
writer.WriteLine( "[登录成功!][用户IP]: " + ip + "; [登录时间]: " + DateTime.Now);
writer.Flush();
writer.Close();
}
}
Response.Redirect( "ManageLogin/ &quo