一个在移动设备中获取路径的方法

一个在移动设备中获取路径的常用方法: 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 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));
            }
        }
这一行代码就制定了当前文件夹下的一个l文件名为log.txt的文件。向里面写一些数据
 
posted @ 2011-03-25 12:50  神一样的疯子  阅读(682)  评论(0编辑  收藏  举报