是否可以使用Windows API代码包设置/编辑文件扩展属性? [英] Is it possible to set/edit a file extended properties with Windows API Code Pack?

查看:266
本文介绍了是否可以使用Windows API代码包设置/编辑文件扩展属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以使用Windows API代码包设置/编辑文件扩展属性(资源管理器:右键单击>属性>详细信息).

I'd like to know if it's possible to set/edit a file extended properties (Explorer: Right-click > Properties > Details) 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);

我使用以下几行来获取所需的属性,但是我不知道如何编辑其中之一(例如艺术家名称). 我知道我可以使用taglib-sharp,但是只有在没有外部代码的情况下没有解决方案时,我才会使用它.

I use these few lines to get the properties I want, but I don't know how to edit one of them (the artist name for example). I know I can use taglib-sharp, but I'll use it only if there is no solution without external code.

谢谢大家花时间帮助我.

Thanks you all for taking the time to help me.

推荐答案

我找到了一种使用ShellPropertyWriter编辑某些属性的方法,但是某些属性是只读的.

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

在此示例中,ShellPropertyWriter.WriteProperty()的前两次出现将完全相同,请编辑文件的"Contributing artist"字段(资源管理器:右键单击>属性">详细信息").第三次调用将引发拒绝访问"异常. 有些是可编辑的,有些则不能.只需尝试.

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.

这篇关于是否可以使用Windows API代码包设置/编辑文件扩展属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆