Winform选择目录路径与选择文件路径

https://blog.csdn.net/zaocha321/article/details/52528279

  • using System.Collections.Generic;
  • using System.ComponentModel;
  • using System.Data;
  • using System.Drawing;
  • using System.Text;
  • using System.Windows.Forms;
  • namespace WindowsApplication1 {
  • public partial class SelectFolder: Form {
  • public SelectFolder()
  • {
  • InitializeComponent();
  • }
  • private void btnSelectPath_Click(object sender, EventArgs e) //弹出一个选择目录的对话框
  • {
  • FolderBrowserDialog path = new FolderBrowserDialog();
  • path.ShowDialog();
  • this.txtPath.Text = path.SelectedPath;
  • }
  • private void btnSelectFile_Click(object sender, EventArgs e) //弹出一个选择文件的对话框
  • {
  • OpenFileDialog file = new OpenFileDialog();
  • file.ShowDialog();
  • this.txtFile.Text = file.SafeFileName;
  • }
  • }

原文地址:https://www.cnblogs.com/LuoEast/p/9871988.html

时间: 2024-08-01 12:48:56

Winform选择目录路径与选择文件路径的相关文章

C# Winform中如何获取文件名与文件路径

获取文件名方法: 用System.IO.Path.GetFileName和System.IO.Path.GetFileNameWithoutExtension(无扩展名)的方法 获取文件路径方法: //获取当前进程的完整路径,包含文件名(进程名).string str = this.GetType().Assembly.Location;result: X:\xxx\xxx\xxx.exe (.exe文件所在的目录+.exe文件名) //获取新的 Process 组件并将其与当前活动的进程关联的

JAVA 取得当前目录的路径/Servlet/class/文件路径/web路径/url地址

JAVA 取得当前目录的路径/Servlet/class/文件路径/web路径/url地址 在写java程序时不可避免要获取文件的路径...总结一下,遗漏的随时补上1.可以在servlet的init方法里String path = getServletContext().getRealPath("/");这将获取web项目的全路径例如 :E:\eclipseM9\workspace\tree\tree是我web项目的根目录 2.你也可以随时在任意的class里调用this.getCla

java 弹出选择目录框(选择文件夹),获取选择的文件夹路径

1 int result = 0; 2 File file = null; 3 String path = null; 4 JFileChooser fileChooser = new JFileChooser(); 5 FileSystemView fsv = FileSystemView.getFileSystemView(); //注意了,这里重要的一句 6 System.out.println(fsv.getHomeDirectory()); //得到桌面路径 7 fileChooser

[MFC]选择目录对话框和选择文件对话框 [转]

在MFC编程中经常会需要用到选择目录和选择文件的界面,以下总结一下本人常用的这两种对话框的生成方法: 选择目录对话框 {    char szPath[MAX_PATH];     //存放选择的目录路径     CString str;    ZeroMemory(szPath, sizeof(szPath));       BROWSEINFO bi;       bi.hwndOwner = m_hWnd;       bi.pidlRoot = NULL;       bi.pszDis

[MFC]选择目录对话框和选择文件对话框

制作选择目录和选择文件对话框,一般用到BROWSEINFO结构,如下: BROWSEINFO结构: HWND hwndOwner,指定对话框的父窗口的句柄 LPCITEMIDLIST pidlRoot,指定打开浏览的根目录,若为NULL,表示桌面 LPSTR pszDisplayName,指定一个缓冲区,接收用户选择的目录的显示名称 LPCSTR lpszTitle,树形视图上方显示的文字 UINT ulFlags,指定属性 BFFCALLBACK Lpfn,指定回调函数,发生某些事件时,指定的

python获取当前文件路径以及父文件路径

1 2 3 4 5 6 #当前文件的路径 pwd = os.getcwd() #当前文件的父路径 father_path=os.path.abspath(os.path.dirname(pwd)+os.path.sep+".") #当前文件的前两级目录 grader_father=os.path.abspath(os.path.dirname(pwd)+os.path.sep+"..")   第一种方法: os.path.abspath(__file__) 假设ap

php根据文件全路径抓取文件路径信息

php中有pathinfo函数来获取文件的路径信息,一般只要传入文件的全路径即可,具体的使用,如下代码示例: <?php $testPathInfo = pathinfo(__FILE__); var_dump($testPathInfo); echo pathinfo(__FILE__,PATHINFO_DIRNAME).'<br/>';//文件的父目录 echo pathinfo(__FILE__,PATHINFO_BASENAME).'<br/>';//文件的全名 ec

Python获取当前文件路径及父文件路径

import os # 当前文件的路径 1.os.getcwd(): 2.os.path.realpath(__file__) # 当前文件的父路径 1.pwd=os.getcwd()   os.path.abspath(os.path.dirname(pwd)+os.path.sep+".") : 2.os.path.dirname(os.path.realpath(__file__)) # 当前文件的前两级目录 1.pwd=os.getcwd()   os.path.abspath

flask 指定前端文件路径以及静态文件路径

flask 默认的 前端路径再 templates下,静态文件再 static下 如果不移动或者修改 app默认路径,可以直接这样写: 1 app = Flask(__name__) 如果有修改,可以这样写: 1 app = Flask(__name__,template_folder='../xxxx',static_folder="../xxxx") 2 3 #template_folder='../xxxx' 指 前端文件的目录 4 #static_folder="..

写一个函数,尽可能高效的,从一个标准 url 里取出文件的扩展名?pathinfo文件路径&amp; parse_url解析url &amp; basename路径中文件名

例如: http://www.sina.com.cn/abc/de/fg.php?id=1 需要取出 php 或 .php 方案1 <?php function getExt($url){ $arr = parse_url($url); $file = basename($arr['path']); $ext = explode(".",$file); return $ext[1]; } echo getExt("http://www.sina.com.cn/abc/d