欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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#通過文件路徑獲取文件名小技巧

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”

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

相關(guān)文章

最新評論