C# Word- Dokumenteneigenschaften auslesen

alebec7

Ensign
Registriert
Juni 2008
Beiträge
154
Hallo, ich will aus einem Word- Dokument (2007) die Eigenschaften (Autor, Betreff, Schlüsselwörter...) auslesen. Leider habe ich aber nur VB- Code gefunden und keinen für C#.

Bitte um Hilfe!
 
Ich habs mit der Klasse "Microsoft.Office.Interop.Word" hinbekommen:

Code:
 object Missing = System.Reflection.Missing.Value;
            object BuiltInProps;
            //object CustomProps;
            object n = System.Reflection.Missing.Value;
            object docName = pOrt;
            object onlyread = true;
            object save = false;
            string PropValue = string.Empty;
            
            Word._Document Doc;
            Word.ApplicationClass MyWord = new Word.ApplicationClass();

            //MyWord.Visible = true;
            Doc = MyWord.Documents.Open(ref docName, ref n, ref onlyread, ref n, ref n, ref n,
                                        ref n, ref n, ref n, ref n, ref n, ref n, ref n, ref n, ref n, ref n);
            BuiltInProps = Doc.BuiltInDocumentProperties;

            Type TypeBuiltingProp = BuiltInProps.GetType();

            //Hole den Wert aus dem entsprechendem Feld:
            string Prop = "Keywords"; //"Keywords", "Author", "Title", "Category" sind möglich
            object CatProp = TypeBuiltingProp.InvokeMember("item",
                                                           BindingFlags.Default | BindingFlags.GetProperty, null,
                                                           BuiltInProps, new Object[] {Prop});
            Type TypeAuthorProp = CatProp.GetType();
            PropValue =
                TypeAuthorProp.InvokeMember("Value", BindingFlags.Default | BindingFlags.GetProperty, null,
                                            CatProp, new Object[] {}).ToString();
 
Zurück
Oben