C#でファイルの拡張プロパティを取得/編集する方法

 

  • NuGetでWindowsAPICodePack-Shellをインストール。
  • 以下のコードで取得/編集ができる。
    using Microsoft.WindowsAPICodePack.Shell;
    using Microsoft.WindowsAPICodePack.Shell.PropertySystem;

    public void FilePropertiesTest() {
        var file = ShellFile.FromFilePath(@"C:\Temp\test.jpg");
        //拡張プロパティ取得
        Console.WriteLine(file.Properties.System.Title.Value);
        Console.WriteLine(file.Properties.System.Author.Value);
        Console.WriteLine(file.Properties.System.Comment.Value);

        //拡張プロパティセット
        ShellPropertyWriter propertyWriter =  file.Properties.GetPropertyWriter();
        propertyWriter.WriteProperty(SystemProperties.System.Title, new string[] { "タイトル" });
        propertyWriter.WriteProperty(SystemProperties.System.Author, new string[] { "著者" });
        propertyWriter.WriteProperty(SystemProperties.System.Comment, new string[] { "コメント" });
        propertyWriter.Close();
    }

0 件のコメント:

コメントを投稿

POKUDA AI高画質化工房サポートページ

当製品に関する問い合わせはこのコメント欄へお願いします