簡體   English   中英

是否可以使用Windows API代碼包設置/編輯文件擴展屬性?

[英]Is it possible to set/edit a file extended properties with Windows API Code Pack?

我想知道是否可以使用Windows API代碼包設置/編輯文件擴展屬性(資源管理器:右鍵單擊>屬性>詳細信息)。

var shellFile = Microsoft.WindowsAPICodePack.Shell.ShellObject.FromParsingName(filePath);
var artistName = shellFile.Properties.GetProperty(SystemProperties.System.Music.DisplayArtist).ValueAsObject.ToString();
var duration = TimeSpan.FromMilliseconds(Convert.ToDouble(shellFile.Properties.GetProperty(SystemProperties.System.Media.Duration).ValueAsObject) * 0.0001);

我使用以下幾行來獲取所需的屬性,但是我不知道如何編輯其中之一(例如藝術家名稱)。 我知道我可以使用taglib-sharp,但是只有在沒有外部代碼的情況下沒有解決方案時,我才會使用它。

謝謝大家花時間幫助我。

我找到了一種使用ShellPropertyWriter編輯某些屬性的方法,但是某些屬性是只讀的。

var shellFile = ShellFile.FromParsingName(filePath);
ShellPropertyWriter w = shellFile.Properties.GetPropertyWriter();
try
{
    w.WriteProperty(SystemProperties.System.Author, new string[] { "MyTest", "Test" });
    w.WriteProperty(SystemProperties.System.Music.Artist, new string[] { "MyTest", "Test" });
    w.WriteProperty(SystemProperties.System.Music.DisplayArtist, "Test");
}
catch (Exception ex)
{

}
w.Close();

在此示例中, ShellPropertyWriter.WriteProperty()ShellPropertyWriter.WriteProperty()將完全相同,請編輯文件的“ Contributing ShellPropertyWriter.WriteProperty() ”字段(資源管理器:右鍵單擊>“屬性”>“詳細信息”)。 第三次調用將引發“訪問被拒絕”異常。 有些是可編輯的,有些則不能。 只需要嘗試。

您可以寫信給ShellFile直接通過設置屬性的值,而不ShellPropertyWriter

var shellFile = ShellFile.FromFilePath(filePath);

shellFile.Properties.System.Author.Value = new string[] { "MyTest", "Test" };
shellFile.Properties.System.Music.Artist.Value = new string[] { "MyTest", "Test" };
shellFile.Properties.System.Music.DisplayArtist.Value = "Test";

請注意,要能夠編輯文件的特定於編解碼器的字段,必須在計算機上安裝編解碼器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM