以编程方式修改文件属性 [英] Modify file properties programmatically

查看:108
本文介绍了以编程方式修改文件属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以编程方式修改文件的属性,尤其是在右键单击文件时在摘要"选项卡下的详细信息:标题,主题,作者,类别,注释.
有人知道如何在C ++或C#中执行此操作吗?

I need to modify a file''s properties programmatically, specifically the details under the ''Summary'' tab when you right click on a file: Title, Subject, Author, Category, Comments.
Anybody know how to do this in C++ or C#?

推荐答案

您可以使用
You can modify these properties using the Microsoft Developer Support OLE File Property Reader available here[^]. When you have installed this, it allows you to manipulate the underlying OleStorage. Here''s a code sample:
private void ChangeProp(string file, string author)
{
  DSOFile.OleDocumentPropertiesClass documentProperties = new DSOFile.OleDocumentPropertiesClass();
  DSOFile.SummaryProperties summaryProperties;

  try
  {
    documentProperties.Open(file, false, DSOFile.dsoFileOpenOptions.dsoOptionDefault);

    summaryProperties = documentProperties.SummaryProperties;
    summaryProperties.Author = author;
    documentProperties.Save();
  }
  finally
  {
    summaryProperties = null;
    documentProperties = null;
  }
}


我认为您是在谈论Office文件.
对于doc,xls,ppt文件,此文件存储在http://msdn.microsoft.com/zh-cn/library/aa380369(VS.85).aspx下(该链接损坏了,这将导致您定义结构化存储).
对于docx,xl​​sx,pptx文件(实际上是zip文件),我不记得了.您可以阅读有关ODF规范的内容.
请注意,使用Office Automation打开所有这些文件将更加容易,这将使您只需很少的代码即可设置这些属性.
I assume you''re talking about office files.
for doc,xls,ppt files this is stored under http://msdn.microsoft.com/en-us/library/aa380369(VS.85).aspx (damn links are broken, this will lead you to definition of structured storage).
for docx,xlsx,pptx files, which are really zip files, I can''t remember. You may which to read up on the ODF specification.
Note that you will have an easier task opening all these files with Office Automation, which will allow you to set these properties with little code.


这篇关于以编程方式修改文件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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