目录C#获取文件名和文件路径方法一方法二C#通过文件路径获取文件名小技巧C#获取文件名和文件路径 方法一 OpenFileDialog open = new OpenFileDia
OpenFileDialog open = new OpenFileDialog();
open.RestoreDirectory = true;
string fullname = open.FileName;
string path = System.io.Path.GetDirectoryName(fullname);//路径
string name = System.IO.Path.GetFileName(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); //截取文件名
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”
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。
--结束END--
本文标题: C#获取文件名和文件路径的两种实现方式
本文链接: https://www.lsjlt.com/news/164918.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0