一个在移动设备中获取路径的方法
一个在移动设备中获取路径的常用方法: public string GetFileName() { return System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase),"filename"); } 在移动设备开发中,路径都使用绝对路
一个在移动设备中获取路径的常用方法:
public string GetFileName()
{
return System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase),"filename");
}
在移动设备开发中,路径都使用绝对路径。
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase 获得应用程序的基目录,然后与文件与装配,就得到了绝对路径。
public string GetFileName()
{
return System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase),"filename");
}
在移动设备开发中,路径都使用绝对路径。
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase 获得应用程序的基目录,然后与文件与装配,就得到了绝对路径。
public void WriteLog(string content,string name)
{
string filepath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.ToString()) + "\\Log\\" ;
if (!Directory.Exists(filepath))
Directory.CreateDirectory(filepath);
string filename = string.Format("{0}\\{1}.txt", filepath, name);
using (StreamWriter sw = new StreamWriter(filename, true))
{
sw.WriteLine(string.Format("{0}",content));
}
}
{
string filepath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.ToString()) + "\\Log\\" ;
if (!Directory.Exists(filepath))
Directory.CreateDirectory(filepath);
string filename = string.Format("{0}\\{1}.txt", filepath, name);
using (StreamWriter sw = new StreamWriter(filename, true))
{
sw.WriteLine(string.Format("{0}",content));
}
}
这一行代码就制定了当前文件夹下的一个l文件名为log.txt的文件。向里面写一些数据