Khaw'la Karray
Khaw'la Karray

Reputation: 11

Author of a file using c#

i want to get the author of a file i used this but it's return the pc\user (khawla-pc\khawla) which is not the real author (Ines). can someone help me?

 string path="D:/testUsers/Auteurs connus/ff_ines.docx";
        string user = System.IO.File.GetAccessControl(path).GetOwner(typeof(System.Security.Principal.NTAccount)).ToString();
        Console.WriteLine(user);

Upvotes: 1

Views: 2573

Answers (1)

christophano
christophano

Reputation: 935

To get the author of a word (2007+) document, you can use the OpenXml library and access the PackageProperties of the document.

public string GetAuthor(string documentPath)
{
    using (var document = WordprocessingDocument.Open(documentPath, false))
    {
        return document.PackageProperties.Creator;
    }
}

Upvotes: 5

Related Questions