C#(asp.net | asp.net core)

Visual Studio C#에서 폴더 탐색창, 파일 탐색창 띄우기

나는아이스크림 2020. 10. 30. 15:05
728x90

폴더 탐색창 띄우는 방법

 

1. Package Manager Console 창에서 

Install-Package WindowsAPICodePack-Shell -Version 1.1.1 입력 후 Enter

 

2. 코드 입력

필요한 using 구문

using Microsoft.WindowsAPICodePack.Dialogs;

 

// 폴더 오픈창 생성 및 설정
CommonOpenFileDialg dl = new CommonOpenFileDialog();
dl.IsFolderPicker = true;
dl.Multiselect = true;

// 폴더 탐색기를 열어서 열기를 눌렀을 때
string[] pathDirs = null;
if(dl.ShowDialog() == CommonFileDialogResult.Ok) {
	pathDir = dl.FileNames.ToArray();
}
else {
	return;
}

 

폴더 선택 창

 


 

파일 탐색창 띄우는 방법

// 파일 오픈창 생성 및 설정
OpenFileDialog dl = new OpenFileDialog();
// 다이얼로그 타이틀 설정
dl.Title = "파일 선택";
dl.Multiselect = true;

// 파일 오픈창 로드
string[] pathFiles = null;
if(dl.ShowDialog() == DialogResult.OK) {
	pathFiles = dl.FileNames.ToArray();
}
else {
	return;
}

 

파일 선택 창

 

728x90
728x90