1. Microsoft.WindowsAPICodePack로 추가된 CommonOpenFileDialog
Microsoft.WindowsAPICodePack를 누겟에 추가해야함.
CommonOpenFileDialog를 치면 오류가 필요한 누겟 설치가 뜸. 자동완성 시켜서 사용하면 됨.
2. Windows.Forms 에서 사용하던 FolderBrowserDialog
샘플 코드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.WindowsAPICodePack.Dialogs; | |
using System; | |
class FileDialogSample | |
{ | |
public static void Main() | |
{ | |
// Microsoft.WindowsAPICodePack.Dialogs | |
using (var dialog = new CommonOpenFileDialog { IsFolderPicker = true }) { | |
if (dialog.ShowDialog() == CommonFileDialogResult.Ok) { | |
Console.WriteLine(dialog.FileName); | |
} else { | |
return; | |
} | |
} | |
// System.Windows.Forms | |
using (var dialog = new System.Windows.Forms.FolderBrowserDialog()) { | |
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { | |
Console.WriteLine(dialog.SelectedPath); | |
} | |
} | |
} | |
} |
반응형
'Programming > C/C++/C#' 카테고리의 다른 글
정규 표현식 Regex (0) | 2021.12.31 |
---|---|
C# Random(min, max) (0) | 2020.05.06 |
미리 예약된 attribute 로 코드 정보 받아오기 (0) | 2020.04.18 |
C# Dictionary enum key 사용 시 GC 확인 (0) | 2020.02.23 |
C# 파일 감시자(FileSystemWatcher) 예제 (0) | 2019.11.06 |
C# Xamarin Mac에 페어링 (0) | 2019.04.26 |
C# Xamarin 예제 따라하기 (0) | 2019.04.24 |
C# Tesseract OCR (0) | 2019.03.30 |