Search code examples
c#pdfexplorerpdfsharpfile-attributes

PdfSharp does not change file system info


I'm writing a program that changes the modification date of all files in a directory.

I can apparantly change the properties, but not for windows to recognize it.

private static void ChangeDateTypeOfFile(DateTime date, string filepath)
{
    int state = PdfReader.TestPdfFile(filepath);
    if (state != 0)
    {
        System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
        PdfDocument doc = PdfReader.Open(filepath);
        doc.Info.ModificationDate = date;
        doc.Save(filepath);
    }
    else
    {
        Console.WriteLine(state);
    }
}

When I read the property before and after I change it I can see the difference and it seems to work. Yet in Windows File Explorer I can't see any changes (nor with title and author for example). And the last modified date changes to when I ran the code.
How can I persistently change this information?

Edit:
When I open it with Notepad I can see the line:

/ModDate(D:20070129000000+01'00') //Set the date to 2007

Why does the file Explorer not display this information?


Solution

  • Why does the file Explorer not display this information?

    Because your code is setting the PDF's internal modification date, that is stored as metadata inside that PDF. This date intentionally has nothing to do with Windows' file timestamps, as these can easily be set to arbitrary values by all sorts of tools, whereas the PDF modification date can only be set by a PDF editor tool.