Introduction
This application will help thoes who wants to change file properties such as date of creation, modification and last acess date.
Background
I was also in search of ultility which will help me to change any files properties such as date of creation, modifcation and last access date. I found many but only the problem was if I changed date of file by using those application, it will add text such as this date has been changed by using so and so application. I done more research and finally I found this solution.
Using the code
Basically for changing these file attributes we need to include follwing namespace.
For developing this application we need openFileDialog box, which will provide file name with its physical location. Then this file passed as a parameter to FileInfo
which provide the entire properties related to file. FileInfo provides functionality to get and set value for certain properties such as date of Creation, Modification and Last Access.
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
txtFileName.Text = openFileDialog1.FileName;
if (txtFileName.Text.Trim() != "")
{
string fn = openFileDialog1.FileName;
FileInfo fileIn = new FileInfo(fn);
lblOriCreationDate.Text = fileIn.CreationTime.ToString();
lblOrigModifiedDate.Text = fileIn.LastWriteTime.ToString();
lblOrigLastAccessDate.Text = fileIn.LastAccessTime.ToString();
pnlChangingAtt.Visible = true;
}
}
On button1_Click open file dialog box, then select file. It will show file name in textBox and its respective dates. Now we want to change dates, just select date from respective DateTimePicker and click on change. This change all respective date and show it below Changed File Information.
Internally on button1_Click it will get file name and based on that it will get FileInfo.
private void btnChange_Click(object sender, EventArgs e)
{
if (txtFileName.Text.Trim() != "")
{
string fn = openFileDialog1.FileName;
FileInfo fileIn = new FileInfo(fn);
ChangeFileAttribute(fileIn);
MessageBox.Show("File information has been changed");
}
}
public void ChangeFileAttribute(FileInfo Fln)
{
Fln.CreationTime =dtpCreationDate.Value.Date;
Fln.LastWriteTime = dtpModification.Value.Date;
Fln.LastAccessTime=dtpLastAccessDate.Value.Date;
lblChangedCreated.Text = Fln.CreationTime.ToString();
lblChangedModified.Text = Fln.LastWriteTime.ToString();
lblChangedAccessDate.Text = Fln.LastAccessTime.ToString();
}
After getting FileInfo
just get respective properties as CreationTime
, LastWriteTime
and LastAccessTime
set those propeties with desire dates.