How to open a file in C # and change its properties?

I need to open a Microsoft Word 2003 file and change its properties. For example, changing a topic on the Summary tab.
alt text

+3
source share
2 answers

Microsoft provides a very useful small build called DSOFile. With a link to it in your project, you can change the properties of the Office document. This does not necessarily allow you to open the actual Office file properties dialog, but you could simulate it.

According to Microsoft:

Dsofile.dll files allow editing Office document properties when Office is not installed

More information and a download link can be found at http://support.microsoft.com/kb/224351

( ) VB, . , # , , . , :

Private Sub ProcessOfficeDocument(ByVal fileName As String)
    Dim docDSO As New DSOFile.OleDocumentPropertiesClass
    Dim docTitle, docModified, docAuthor, docKeywords As String
    Try
        docDSO.Open(fileName, True)
        Dim docSummary As DSOFile.SummaryProperties = docDSO.SummaryProperties
        docTitle = docSummary.Title
        docAuthor = docSummary.Author
        docKeywords = docSummary.Keywords
        docModified = CStr(docSummary.DateLastSaved)

        If (Not String.IsNullOrEmpty(docTitle)) Then
            _Title = docTitle
        End If

        If (Not String.IsNullOrEmpty(docAuthor)) Then
            _Author = docAuthor
        End If

        If (Not String.IsNullOrEmpty(docModified)) Then
            _DateModified = DateTime.Parse(docModified)
        End If

    Catch ex As Exception
        'Do whatever you need to do here...'
    Finally
        If (Not docDSO Is Nothing) Then
            docDSO.Close()
        End If
    End Try
End Sub
+8

:

, , , Word .

+5

Source: https://habr.com/ru/post/1698269/


All Articles