Rocky Singh
Rocky Singh

Reputation: 15430

Maintain last modified date for a file between server and local machine

I am making FileSync kind of service between the server where my website is hosted and my local machine (windows app). From my machine I want to download a file only if it is modified at server.

After investigating on how to do that I came to know that I can compare "Last date modified" of that file on server to what it is on my local machine. Lets say I have this file:

enter image description here

I am downloading this file via stream to my local machine via C# windows app. When the file is downloaded on my machine its "date modified" gets changed. I have two questions here:

How to preserve Last Date modified what was on server?

How should I consider the timezones difference of my machine and
server machine?

Upvotes: 3

Views: 1567

Answers (1)

Markus Safar
Markus Safar

Reputation: 6580

You can reset the date by using the the .LastWriteTime property of an FileInfo instance. I would suggest getting the original date from your file on the server, downloading it and afterwards setting the date of your written file with some code like this:

DateTime originalServerFileTime = ...;

FileInfo fi = new FileInfo(@"YourFile.txt");
fi.LastWriteTime = originalServerFileTime;

Upvotes: 1

Related Questions