亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#獲取文件名和文件路徑的兩種實(shí)現(xiàn)方式

 更新時(shí)間:2022年07月22日 08:52:47   作者:Welcome_Back  
這篇文章主要介紹了C#獲取文件名和文件路徑的兩種實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

C#獲取文件名和文件路徑

方法一

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("http://");  //返回“//”最后一次出現(xiàn)的位置
string filepath = fullpath.Substring(0,index); //截取字符串,0到“//”最后出現(xiàn)的位置
string filename = fullpath.Substring(index+1);  //截取文件名

C#通過(guò)文件路徑獲取文件名小技巧

string fullPath = @"\WebSite1\Default.aspx";

string filename = System.IO.Path.GetFileName(fullPath);//文件名 ?“Default.aspx”
string extension = System.IO.Path.GetExtension(fullPath);//擴(kuò)展名 “.aspx”
string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(fullPath);// 沒(méi)有擴(kuò)展名的文件名 “Default”

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論