栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何设置扩展文件属性?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何设置扩展文件属性?

解决方案2016

将以下NuGet软件包添加到您的项目中:

  • Microsoft.WindowsAPICodePack-Shell
    由Microsoft
  • Microsoft.WindowsAPICodePack-Core
    由Microsoft

读写属性

using Microsoft.WindowsAPICodePack.Shell;using Microsoft.WindowsAPICodePack.Shell.PropertySystem;string filePath = @"C:tempexample.docx";var file = ShellFile.FromFilePath(filePath);// Read and Write:string[] oldAuthors = file.Properties.System.Author.Value;string oldTitle = file.Properties.System.Title.Value;file.Properties.System.Author.Value = new string[] { "Author #1", "Author #2" };file.Properties.System.Title.Value = "Example Title";// Alternate way to Write:ShellPropertyWriter propertyWriter =  file.Properties.GetPropertyWriter();propertyWriter.WriteProperty(SystemProperties.System.Author, new string[] { "Author" });propertyWriter.Close();

重要:

该文件必须是有效的,由特定的分配软件创建。每种文件类型都有特定的扩展文件属性,但并非所有文件都是可写的。

如果右键单击桌面上的文件而无法编辑属性,则也将无法在代码中对其进行编辑。

例:

  • 在桌面上创建txt文件,将其扩展名重命名为docx。您无法编辑其
    Author
    Title
    属性。
  • 用Word打开它,编辑并保存。现在你可以。

因此,请确保使用一些

try
catch

进一步的主题: MSDN:实现属性处理程序



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/470735.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号