Kaz*_*aze 6 c# file-properties 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);
Run Code Online (Sandbox Code Playgroud)
我使用以下几行来获取所需的属性,但是我不知道如何编辑其中之一(例如艺术家名称)。我知道我可以使用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();
Run Code Online (Sandbox Code Playgroud)
在此示例中,第一次出现的 2 次ShellPropertyWriter.WriteProperty()
将执行完全相同的操作,编辑文件的“贡献艺术家”字段(资源管理器:右键单击 > 属性 > 详细信息)。第三次调用将抛出“访问被拒绝”异常。有些是可编辑的,有些则不可编辑。只需要尝试一下。
归档时间: |
|
查看次数: |
4071 次 |
最近记录: |