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 件のコメント:

コメントを投稿

厳選 Visual Studioの便利なショートカット

  エラー箇所にジャンプ 「Ctrl + Shift + F12」 ブレークポイント 設定/解除 「F9」 有効化/無効化 「Ctrl + F9」 ViEmu特有 「:ls」:バッファナンバーのリストを表示。 「:b2」:バッファ2のファイルを開く。 「:n」:次のバッファのファ...