Search code examples
c#winforms.doc

Application freezes when trying to read Author from .doc multiple files


I'm trying to make an app that displays all authors of .doc files from a Folder and its subfolders, the problem is that I used Directory.GetFiles("*.doc", SearchOption.AllDirectories) and when I'm trying to read from a folder with very much files, the app freeze in this point. Here is my code

FileInfo[] Files = dir.GetFiles("*.doc", SearchOption.AllDirectories);
foreach(FileInfo file in Files) 
{
    try
    {
        //ConvertDOCToDOCX(file.FullName);
        using(WordprocessingDocument sourcePresentationDocument = WordprocessingDocument.Open(file.FullName, false)) 
        {
            metadataList.Add(new Metadata() 
            {
                Name = "Title", Value = file.Name
            });
            metadataList.Add(new Metadata() 
            {
                Name = "Author", Value = sourcePresentationDocument.PackageProperties.Creator
            });
            metadataList.Add(new Metadata() 
            {
                Name = "", Value = ""
            });
        }
    }
}

Solution

  • I think you dont need this "WordprocessingDocument" - this is producing a heavy load - you can just read the meta-information via .net default file methods.

    For an example, you should take a look at Read/Write 'Extended' file properties (C#)