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

余生颓废 提交于 2019-12-01 17:15:17

I found a way to edit some properties with ShellPropertyWriter but some properties are read-only.

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();

In this sample, the 2 first occurences of ShellPropertyWriter.WriteProperty() will do exactly the same, edit the "Contributing artists" field of the file (Explorer: Right-click > Properties > Details). The third call will throw an "Access denied" exception. Some are editable, others are not. Just need to try.

You can write to the ShellFile directly by setting the value of the properties without 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";

Just be aware, that to be able to edit codec-specific fields of a file, it's necessary to have the codec installed on the computer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!