Search code examples
c#windows-mobilecompact-frameworkpinvokecreation

C# P/Invoke Attribute


New to C# Compact edition 6.5. I am trying to set the datetime on a file which seems to be off by 5 hours from the actual system time. I am doing only this to create the file:

        FileStream fs= File.Create(name);  

Just doing this the Created date is 5 hours ahead...if I try and set the CreationTime I get a compile error saying the Attribute is Readonly, seriously?

        FileInfo fi = new FileInfo(name);
        fi.CreationTime = date;

So my question is since I am new to C# how do you get access to a "readonly" Attribute in the CE framework? I see mentioning of P/Invoke but seems to work on methods only and not attributes. Anyone can given a quick demo on how to do this?

I've tried this solution and still get the file writing UTC even though I send it the current local time


Solution

  • I just ran this:

    [MTAThread]
    static void Main()
    {
        var name = "\\foo.txt";
        var info = new FileInfo(name);
        using (info.Create()) { }
        info.Refresh();
        var createTime = info.CreationTime;
        var now = DateTime.Now;
        var delta = now - createTime;
        Debug.WriteLine(delta.ToString());
    }
    

    And got this output:

    00:00:00.0140000

    Which seems to be correct to me.