Home >Backend Development >C++ >How Can I Modify Extended File Properties (Like Company) in Word or PDF Documents Using .NET?

How Can I Modify Extended File Properties (Like Company) in Word or PDF Documents Using .NET?

DDD
DDDOriginal
2025-01-05 13:17:41449browse

How Can I Modify Extended File Properties (Like Company) in Word or PDF Documents Using .NET?

Setting Extended File Properties in .NET

If you need to modify the Company field value or other extended file properties within Word or PDF documents, here's how you can do it using .NET:

  1. Install NuGet Packages:
    Add the following NuGet packages to your project:

    • Microsoft.WindowsAPICodePack-Shell
    • Microsoft.WindowsAPICodePack-Core
  2. Read and Write Properties:
    In your C# code, use the Microsoft.WindowsAPICodePack.Shell and Microsoft.WindowsAPICodePack.Shell.PropertySystem namespaces to read and write file properties. Here's an example:
using Microsoft.WindowsAPICodePack.Shell;
using Microsoft.WindowsAPICodePack.Shell.PropertySystem;

string filePath = @".\example.docx";
var file = ShellFile.FromFilePath(filePath);

// Read the old properties
string[] oldAuthors = file.Properties.System.Author.Value;

The above is the detailed content of How Can I Modify Extended File Properties (Like Company) in Word or PDF Documents Using .NET?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn