Is it possible to set / change extended file properties using the Windows API Code Pack?
I would like to know if the extended properties of a file (explorer: right click> Properties> Details) can be set / changed using the Windows API Code Pack.
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);
I am using these few lines to get the properties I want, but I donβt know how to edit one of them (eg artist name). I know I can use taglib-sharp, but I will only use it if there is no solution without external code.
Thank you all for taking the time to help me.
source to share
I found a way to edit some properties using 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 example, the first two inputs ShellPropertyWriter.WriteProperty()
will do the same, edit the "Contributors artist" field of the file ("Explorer: right click> Properties> Details"). The third call will throw an "Access Denied" exception. Some of them are available for editing, others are not. Just have to try.
source to share
You can write directly by ShellFile
setting the property value 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 keep in mind that to edit the fields of a specific codec file, the codec must be installed on your computer.
source to share