日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

C#獲取文件名和文件路徑的兩種實現方式_C#教程

作者:Welcome_Back ? 更新時間: 2022-09-15 編程語言

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://");  //返回“//”最后一次出現的位置
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”

原文鏈接:https://blog.csdn.net/weixin_51205206/article/details/119875312

欄目分類
最近更新