N. Saw
N. Saw

Reputation: 103

How to set datemodified property for a Storage file in c# uwp?

I need to set specific time for date modified property, not current time.

I can't use FileInfo because the file is located in folder outside \AppData\Local\Packages<packagename>\LocalState (system.io has no access).

Upvotes: 0

Views: 252

Answers (1)

Nico Zhu
Nico Zhu

Reputation: 32785

How to set datemodified property for a Storage file in c# uwp?

UWP has SavePropertiesAsync method that could use to modify basic property, unfortunately, System.DateModified is Innate, so we can't update it manually in uwp platform as this answer said. For this scenario, we suggest update FileInfo use desktop extension, for more you could refer to stefan's blog UWP with Desktop Extension. And the other way is copy the file into app's local folder, and put it back after modified property

The following is sample code that update LastWriteTime within desktop extension

OpenFileDialog openFileDialog = new OpenFileDialog();
if (openFileDialog.ShowDialog() == true)
{
    FileInfo fi = new FileInfo(openFileDialog.FileName);
    fi.LastWriteTime = DateTime.Now;
}

Upvotes: 0

Related Questions