摘要: Path 类 对包含文件或目录路径信息的String实例执行操作。 1.Path.GetExtension 方法 ——返回指定的路径字符串的扩展名。 public static string GetExtension(string path)string fileName = @"C:\mydir.old\myfile.ext";string path = @"C:\mydir.old\";string extension;extension = Path.GetExtension(fileName);Console.WriteLine("Ge 阅读全文
posted @ 2013-07-15 18:38 花落红尘 阅读(1857) 评论(0) 推荐(0) 编辑
摘要: File 类 提供用于创建、复制、删除、移动和打开文件的静态方法,并协助创建FileStream对象。 1. File.Exists ——确定指定的文件是否存在。 public static bool Exists(string path)string curFile = @"c:\temp\test.txt";Console.WriteLine(File.Exists(curFile) ? "File exists." : "File does not exist."); 2. File.AppendAllText 方法 ——将指定 阅读全文
posted @ 2013-07-15 14:58 花落红尘 阅读(2534) 评论(0) 推荐(1) 编辑
摘要: 编写程序的时候,经常需要用的项目根目录。自己总结如下1、取得控制台应用程序的根目录方法 方法1、Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径 方法2、AppDomain.CurrentDomain.BaseDirectory 获取基目录,它由程序集冲突解决程序用来探测程序集2、取得Web应用程序的根目录方法 方法1、HttpRuntime.AppDomainAppPath.ToString();//获取承载在当前应用程序域中的应用程序的应用程序目录的物理驱动器路径。用于App_Data中获取 方法2、Server.MapPath("& 阅读全文
posted @ 2013-07-15 10:00 花落红尘 阅读(140) 评论(0) 推荐(0) 编辑