網站首頁 編程語言 正文
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
相關推薦
- 2023-02-26 C++?ROS與boost:bind()使用詳解_C 語言
- 2022-09-02 Docker下Redis集群(主從+哨兵)安裝配置的實現步驟_docker
- 2022-10-23 Redis?異常?read?error?on?connection?的解決方案_Redis
- 2022-01-05 webpack——Loader示例:打包css文件
- 2022-10-14 yum-config-manager 命令找不到的解決方法
- 2023-07-09 Golang syncMap 詳解
- 2022-07-19 AI與Python人工智能啟發式搜索概念理解_python
- 2024-04-06 linux中redis重啟,啟動,停止的sh腳本
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支