Guten Abend,
ich arbeite momentan an einem Programm, welches die erweiterten Dateieigenschaften von Dateien verändern kann.
Es soll speziell für Office-Dateien funktionieren (doc, docx, ppt, pptx, xls, xlsx).
Bis jetzt funktioniert es ganz gut, aber leider nur für die alte Dateiversion, also doc, ppt und xls. Bei dem neuen Dateiformat mit x scheitert es mit folgendem Fehler:
Mein Code (Funktion):
Kann mir jemand helfen, wie man das ganze auch für .docx und .pptx etc Dateien zum Laufen bringt? Danke.
Grüße,
Michdi
Gesamter Code:
Spoiler anzeigen
ich arbeite momentan an einem Programm, welches die erweiterten Dateieigenschaften von Dateien verändern kann.
Es soll speziell für Office-Dateien funktionieren (doc, docx, ppt, pptx, xls, xlsx).
Bis jetzt funktioniert es ganz gut, aber leider nur für die alte Dateiversion, also doc, ppt und xls. Bei dem neuen Dateiformat mit x scheitert es mit folgendem Fehler:
Unable to get writable property store for this property.
Mein Code (Funktion):
VB.NET-Quellcode
- Dim verzeichnis As String = "E:\Documents\"
- Public Function applyProperty(ByRef author As String, ByRef title As String, ByRef comment As String, ByRef subject As String, ByRef company As String, ByRef category As String, ByRef keywords As String) As Boolean
- Dim di As New DirectoryInfo(verzeichnis)
- Dim fiArr As FileInfo() = di.GetFiles()
- Dim fri As FileInfo
- For Each fri In fiArr
- If (fri.Extension.ToLower = ".doc") Then
- Try
- Dim filePath As String = fri.FullName
- Dim file As ShellFile = ShellFile.FromFilePath(filePath)
- Dim oldAuthors() As String = file.Properties.System.Author.Value
- Dim oldTitle As String = file.Properties.System.Title.Value
- Dim propertyWriter As ShellPropertyWriter = file.Properties.GetPropertyWriter
- propertyWriter.WriteProperty(SystemProperties.System.Author, New String() {author})
- propertyWriter.WriteProperty(SystemProperties.System.Title, New String() {title})
- propertyWriter.WriteProperty(SystemProperties.System.Comment, New String() {comment})
- propertyWriter.WriteProperty(SystemProperties.System.Subject, New String() {subject})
- propertyWriter.WriteProperty(SystemProperties.System.Company, New String() {company})
- propertyWriter.WriteProperty(SystemProperties.System.Category, New String() {category})
- propertyWriter.WriteProperty(SystemProperties.System.Keywords, New String() {keywords})
- propertyWriter.Close()
- Catch ex As Exception
- MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
- Clipboard.SetText(ex.Message)
- End Try
- End If
- Next fri
- Return True
- End Function
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- applyProperty(title:=tbTitle.Text, author:=tbAuthor.Text, category:=tbCategory.Text, comment:=tbCommentary.Text, company:=tbCompany.Text, keywords:=tbKeyword.Text)
- End Sub
Kann mir jemand helfen, wie man das ganze auch für .docx und .pptx etc Dateien zum Laufen bringt? Danke.
Grüße,
Michdi
Gesamter Code:
VB.NET-Quellcode
- Imports Microsoft.WindowsAPICodePack.Shell
- Imports Microsoft.WindowsAPICodePack.Shell.PropertySystem
- Imports Microsoft.WindowsAPICodePack
- Imports System.IO
- Public Class Form1
- Dim verzeichnis As String = "E:\Documents\"
- Public Function applyProperty(ByRef author As String, ByRef title As String, ByRef comment As String, ByRef subject As String, ByRef company As String, ByRef category As String, ByRef keywords As String, ByRef fileformat As String) As Boolean
- Dim di As New DirectoryInfo(verzeichnis)
- Dim fiArr As FileInfo() = di.GetFiles()
- Dim fri As FileInfo
- For Each fri In fiArr
- If (fri.Extension.ToLower = ".docx") Then
- 'MsgBox(fri.FullName)
- Try
- Dim filePath As String = fri.FullName
- Dim file As ShellFile = ShellFile.FromFilePath(filePath)
- Dim oldAuthors() As String = file.Properties.System.Author.Value
- Dim oldTitle As String = file.Properties.System.Title.Value
- Dim propertyWriter As ShellPropertyWriter = file.Properties.GetPropertyWriter
- propertyWriter.WriteProperty(SystemProperties.System.Author, New String() {author})
- propertyWriter.WriteProperty(SystemProperties.System.Title, New String() {title})
- propertyWriter.WriteProperty(SystemProperties.System.Comment, New String() {comment})
- propertyWriter.WriteProperty(SystemProperties.System.Subject, New String() {subject})
- propertyWriter.WriteProperty(SystemProperties.System.Company, New String() {company})
- propertyWriter.WriteProperty(SystemProperties.System.Category, New String() {category})
- propertyWriter.WriteProperty(SystemProperties.System.Keywords, New String() {keywords})
- propertyWriter.Close()
- Catch ex As Exception
- MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
- Clipboard.SetText(ex.Message)
- End Try
- End If
- Next fri
- Return True
- End Function
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- lblStatus.Text = "Arbeitet..."
- If (applyProperty(title:=tbTitle.Text, author:=tbAuthor.Text, category:=tbCategory.Text, comment:=tbCommentary.Text, company:=tbCompany.Text, fileformat:="doc", keywords:=tbKeyword.Text, subject:=tbSubject.Text) = True) Then
- lblStatus.Text = "Fertig!"
- End If
- End Sub
- Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
- FolderBrowserDialog1.ShowDialog()
- verzeichnis = FolderBrowserDialog1.SelectedPath
- pfadBox.Text = verzeichnis
- End Sub
- End Class
Die beste maschinelle Übersetzung der Welt - DeepL Übersetzer
Alle Zitate, die ich seit dem 1.9.2017 übersetzt habe, wurden vollautomatisch mit DeepL übersetzt.
Alle Zitate, die ich seit dem 1.9.2017 übersetzt habe, wurden vollautomatisch mit DeepL übersetzt.