Home >Backend Development >C++ >How Can I Use Microsoft.WindowsAPICodePack to Set Extended File Properties?

How Can I Use Microsoft.WindowsAPICodePack to Set Extended File Properties?

Barbara Streisand
Barbara StreisandOriginal
2024-12-27 16:26:11925browse

How Can I Use Microsoft.WindowsAPICodePack to Set Extended File Properties?

Setting Extended File Properties Using Microsoft.WindowsAPICodePack

Extended file properties, such as Company information, provide valuable metadata for Word and PDF documents. While retrieving these properties is straightforward using shell32.dll, setting them poses a greater challenge. This article explores how to leverage Microsoft.WindowsAPICodePack to effectively alter extended file properties.

Getting Started

To start, install the following NuGet packages:

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

Reading and Writing Properties

Once the packages are installed, you can access and modify properties using the following code:

using Microsoft.WindowsAPICodePack.Shell;
using Microsoft.WindowsAPICodePack.Shell.PropertySystem;

// Get file path
string filePath = @"C:\temp\example.docx";

// Load file
var file = ShellFile.FromFilePath(filePath);

// Get current properties
string[] oldAuthors = file.Properties.System.Author.Value;

The above is the detailed content of How Can I Use Microsoft.WindowsAPICodePack to Set Extended File Properties?. 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