SDF Sample: Altering File Properties

I’d like to adjust the creation/last access/last modification property of a file.  The Compact Framework’s FileSystemInfo class has fields that seem appropriate for these, but they are read only.  While I’m modifying properties of the firl, I’d also like to mark the file as read-only to help prevent accidental deletion. What can the SDF do for me?

The OpenNETCF.IO.FileHelper class provides methods to alter all of these file properties (as well as simple methods for reading files without having to create streams first).  Here is an example of how you could use the FileHelper:

string myFilePath = @”My Documentsmyfile.txt”;

// alter the file creation time
OpenNETCF.IO.FileHelper.SetCreationTime(myFilePath, DateTime.Now);

// make the file hidden and read-only
OpenNETCF.IO.FileHelper.SetAttributes(myFilePath, FileAttributes.Hidden | FileAttributes.ReadOnly);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s