C# - ("Save File Dialog" 등의) 대화 창에 확장 속성을 보이는 방법
아래와 같은 질문이 있군요. ^^
Dialogbox 제목 추가
; https://social.msdn.microsoft.com/Forums/ko-KR/bafce89e-b921-4cd4-b45e-49b34f8b64ce/dialogbox-5122847785-5262844032?forum=dotnetko
닷넷에 기본 포함된 System.Windows.Forms.SaveFileDialog 타입은 다음과 같은 식의 (기본) 대화창을 보여줍니다.
만약, 파일의 확장 속성까지 편집할 수 있는 다음과 같은 식의 대화창을 보여주고 싶다면,
이제는
WindowsAPICodePack의 힘을 빌려야 합니다. 이를 위해 NuGet 패키지 참조를 해야 하는데, 안 본 사이 ^^ WindowsAPICodePack 관련 라이브러리가 많이도 생겼습니다.
우선, 원래의 패키지를 거의 그대로 배포한 버전이 있고,
Windows7APICodePack
; https://www.nuget.org/packages/Windows7APICodePack/
Install-Package Windows7APICodePack
이후 더 이상 유지 보수가 안 되고 있는 이것을 Aybe라는 개발자가 정리한 버전이 있습니다.
WindowsAPICodePack-Core
; https://www.nuget.org/packages/WindowsAPICodePack-Core
Install-Package WindowsAPICodePack-Core
Install-Package WindowsAPICodePack-ExtendedLinguisticServices
Install-Package WindowsAPICodePack-Sensors
Install-Package WindowsAPICodePack-Shell
Install-Package WindowsAPICodePack-ShellExtensions
그런데, Visual Studio NuGet Manager에서 APICodePack으로 검색하면 현재 가장 상단에는 rpastric이라는 개발자가 배포하고 있는 (Aybe의 repo에서 fork한) 버전이 위치하고 있습니다. 일단 저는 이걸로 ^^ 설치해 보겠습니다.
Install-Package Microsoft-WindowsAPICodePack-Shell -Version 1.1.3.3
그다음, 코드를 다음과 같이 작성하면 끝!
Microsoft.WindowsAPICodePack.Dialogs.CommonSaveFileDialog csfd = new Microsoft.WindowsAPICodePack.Dialogs.CommonSaveFileDialog();
csfd.SetCollectedPropertyKeys(true, new PropertyKey[] { SystemProperties.System.Author,
SystemProperties.System.Keywords,
SystemProperties.System.Title });
if (csfd.ShowDialog() != Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialogResult.Ok)
{
return;
}
foreach (var prop in csfd.CollectedProperties)
{
var propKey = prop.PropertyKey;
if (propKey == SystemProperties.System.Author)
{
foreach (var author in prop.ValueAsObject as string [])
{
Trace.WriteLine("Author: " + author);
}
}
else if (propKey == SystemProperties.System.Keywords)
{
foreach (var tag in prop.ValueAsObject as string[])
{
Trace.WriteLine("Keyword: " + tag);
}
}
else if (propKey == SystemProperties.System.Title)
{
Trace.WriteLine("Title: " + prop.ValueAsObject);
}
}
NuGet에서 Microsoft-WindowsAPICodePack-Shell 참조 시 다음과 같은 오류가 발생할 수 있습니다.
Could not install package 'Microsoft-WindowsAPICodePack-Core 1.1.3.3'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
왜냐하면, Microsoft-WindowsAPICodePack-Shell은 4.5.2 이후의 .NET Framework을 지원하기 때문인데 그것보다 낮은 경우 저런 의존성 문제가 발생합니다. 만약 하위 버전에서의 지원이 필요하다면 다른 APICodePack을 사용하면 됩니다.
[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]