string fileNameNo = Path.GetFileName(FileUploadImg.PostedFile.FileName); //获取文件名和扩展名string DirectoryName = Path.GetDirectoryName(FileUploadImg.PostedFile.FileName); //获取文件所在目录string Extension = Path.GetExtension(FileUploadImg.PostedFile.FileName); //获取扩展名string fileName = Path.GetFileNameWithoutExtension(FileUploadImg.PostedFile.FileName); //获取文件名(不包括扩展名)...
代码如下://判断文件路径是否存在,不存在则创建文件夹 if (!System.IO.Directory.Exists(@"D:\Export")) { System.IO.Directory.CreateDirectory(@"D:\Export");//不存在就创建目录 } //判断文件是否存在 添加引用using System.IO; if(File.Exists(@"文件路径")) { //存在 } else { //不存在 }
string Server.MapPath(string path) 返回与Web服务器上的指定虚拟路径相对应的物理文件路径。 Server.MapPath(Request.ServerVariables["PATH_INFO"]) Server.MapPath("/") Server.MapPath("") Server.MapPath(".") Server.MapPath("../") Server.MapPath("..") Page.Request.ApplicationPath (HttpContext.Current.Request.PhysicalApplicationPath); 以上的代码在http://localhost/Engli...
c#核心代码: 代码如下:DirectoryInfo dir = new DirectoryInfo(strPath); foreach (FileInfo fi in dir.GetFiles("*.doc")) { if (fi.FullName.EndsWith(".doc")) // 将 docx 类型的文件过滤掉 { // 这个 fi 就是你要的 doc 文件 Console.WriteLine(fi.Name); } }