目录C#获取文件名和文件路径方法一方法二C#通过文件路径获取文件名小技巧C#获取文件名和文件路径方法一OpenFileDialogopen=newOpenFileDialog();open.R...
目录
C#获取文件名和文件路径方法一
方法二
C#通过文件路径获取文件名小技巧
C#获取文件名和文件路径
方法一

OpenFileDialog open = new OpenFileDialog(); open.RestoreDirectory = true; string fullname = open.FileName; string path = System.IO.Path.GetDirectoryName(fullname);//路径 string name = System.IO.Path.GetFwww.cppcns.comileName(fullname);//名称
方法二

OpenFileDialog open = new OpenFileDialog();
open.RestoreDirectory = true;
string fullpath = open.FileName;
//获取文件路径和文件名
int index = fullpath.LastIndexOf("//"); //返回“//”最后一次出现的位置
string filepath = fullpath.Substring(0,index); //截取字符串,0到“//”最后出现的位置
string filename = fullpath.Substring(index+1); //截取文件名
C#通过文件路径获取文件名小技巧
string fullPath = @"\WebSite1\Default.ASPx"; string filename = System.IO.Path.GetFileName(fullPath);//文件名 “Default.aspx” string extension = System.IO.Path.GetExtension(fullPath);//扩展名 “.aspx” string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(fullPath);// 没有扩展名的文件名 “Default”
以上为个人经验,希望能给大家一个参考,也希望大家多多支持我们。










