3 Replies - 905 Views - Last Post: 04 December 2012 - 09:23 AM Rate Topic: -----

#1 rapo  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 27-November 08

LastAccessTime and LastWriteTime problem on text file reading

Posted 04 December 2012 - 08:00 AM

Hello,
I have a file that is read (parsed into memory) with StreamReader. Originally the file is parsed and closed but the LastAccessTime is changed.
I'm using this code to set the dates as were before opening but it's not working because I still have a difference of couple of seconds between the original datetime and the one after read.

FileInfo original_File_info = new FileInfo(Constants.FilePath);
/* parsing */
/* Streamreader closing*/
File.SetAccessControl(Constants.FilePath, original_File_info.GetAccessControl());
File.SetAttributes(Constants.FilePath, original_File_info.Attributes);
File.SetCreationTimeUtc(Constants.FilePath, original_File_info.CreationTimeUtc);
File.SetLastAccessTimeUtc(Constants.FilePath, original_File_info.LastAccessTimeUtc);
File.SetLastWriteTimeUtc(Constants.FilePath, original_File_info.LastWriteTimeUtc);   





How can be solved this problem?

Is This A Good Question/Topic? 0
  • +

Replies To: LastAccessTime and LastWriteTime problem on text file reading

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5475
  • View blog
  • Posts: 11,759
  • Joined: 02-June 10

Re: LastAccessTime and LastWriteTime problem on text file reading

Posted 04 December 2012 - 08:52 AM

Read the file access time before you access it.
... do your thing
Write the dates back.
Was This Post Helpful? 0
  • +
  • -

#3 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: LastAccessTime and LastWriteTime problem on text file reading

Posted 04 December 2012 - 08:53 AM

So the LastAccessTime is changing when you are reading the file, and you want that value to go back to what it was before you read the file?

Get the LastAccessTimeUtc before you read the file and store it in a DateTime object. After you have completed, use the SetLastAccessTimeUtc(like you are now) and give it the DateTime object that you stored.
Was This Post Helpful? 0
  • +
  • -

#4 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4461
  • View blog
  • Posts: 7,771
  • Joined: 08-June 10

Re: LastAccessTime and LastWriteTime problem on text file reading

Posted 04 December 2012 - 09:23 AM

I'm curious why you'd want to touch a file without appearing to have done so.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1