我知道我可以通过RetrievePropertiesAsync()
方法检索文件的预定义属性。但是现在我想再添加一个我自己的自定义属性,比如描述,有可能吗?我试过这段代码,但是异常
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
StorageFile file = await KnownFolders.MusicLibrary.GetFileAsync("video.mp4");
List<string> propertiesName = new List<string>();
propertiesName.Add("CustomProperty");
string a = "Come and knock on our door. We've been waiting for you. Where the kisses are hers and hers and his, three's company, too! Come and dance on our floor. Take a step that is new. We've a lovable space that needs your face, three's company, too! You'll see that life is a ball again and laughter is callin' for you. Down at our rendezvous, three's company, too! The year is 1987 and NASA launches the last of America's deep space probes. In a freak mishap, Ranger 3 and its pilot Captain William 'Buck' Rogers are blown out of their trajectory into an orbit which freezes his life support system and returns Buck Rogers to Earth five hundred years later.";
IDictionary<string, object> extraProperties = await file.Properties.RetrievePropertiesAsync(propertiesName);
extraProperties.Add((new KeyValuePair<string, object>("CustomProperty", a)));
await file.Properties.SavePropertiesAsync(extraProperties);
}
An exception of type 'System.ArgumentException' occurred in App2.exe but was not handled in user code
WinRT information: The specified property name (CustomProperty) is invalid. The property may not be registered on the system.
Additional information: The parameter is incorrect.
P.S.:我想要像 这这样的东西
发布于 2012-09-29 05:10:46
这些错误似乎表明需要在要检索的属性系统中定义属性。快速的MSDN搜索显示它可以使用PSRegisterPropertySchema函数完成,但它只适用于桌面应用程序。本题更详细地描述了注册自定义属性。由于Windows8中已经有大量内置属性和WinRT,因为它关注的是其基本原理,这在Windows应用程序中不太可能实现。这意味着您可以使用桌面应用程序注册该属性,但是您的商店应用程序如果要通过认证,就不能依赖它的存在。StorageItemContentProperties的文档提到使用QueryOptions查询其他应用程序定义的属性,如果您想搜索其他应用程序定义的属性,可以尝试使用它。
使用另一个应用程序(如Microsoft )定义的属性处理程序获取或设置的注释属性可能无法访问。相反,您可以尝试使用系统索引支持的文件查询来获取这些属性。有关更多信息,请参见QueryOptions。
https://stackoverflow.com/questions/12638866
复制相似问题