error: “Microsoft.WindowsAPICodePack.Shell.PropertySystem.PropertySystemException Unable to get writable property store for this property.”

时间秒杀一切 提交于 2020-01-07 09:45:16

问题


I have created dotnet application which is updating metadata (e.g. "Title" property) of XLSX file.

I am using Microsoft.WindowsAPICodePack.Shell library in my application...which is perfectly updating metadata of that file on development environment.

But on production server that application is not working.

It is giving error like.....

Microsoft.WindowsAPICodePack.Shell.PropertySystem.PropertySystemException (0x80004005): Unable to get writable property store for this property.

Development and Production environment is having same OS installed. Visual Studio and office installed on delvelopment environment. But not on production environment.

Does any one have idea on this?


回答1:


Add following NuGet packages to your project:

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

Read and Write Properties

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

string filePath = @"yourfilepath";
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();


来源:https://stackoverflow.com/questions/59562232/error-microsoft-windowsapicodepack-shell-propertysystem-propertysystemexceptio

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!