Archive for 11th January 2007

Retaining The LastWriteTime Value For A File About To Be Overwritten Via FTP / FileUpload By Using ASP.NET’s FileInfo Class

Recently asked on Yahoo! Answers:

Preserving last modified date when uploading (asp.net)?

I need to preserve (or change) the last modified date in the file headers when uploading via ftp. When I upload a file via ftp, the last modified date will be the date of upload. Creation date would be fine too. I just need to have the original date attached somewhere in the attributes.

Does anyone have a creative solution. For instance, can I create a container with custom attributes and then stream the data into it? If so how would I do it? Links and/or code would be greatly appreciated. Also, I am using vb.net but C# is fine too.

Keep in mind I must pass credentials to the remote server.

This is actually fairly straightforward, thanks to the FileInfo class in .NET — it’s a subclass of the FileSystemInfo class, which is a replacement of the FileSystemObject of yore.

And much like the old FileSystemObject class, FileInfo not only allows us to do some basic things with files — open, close, read, write and delete, for example — it also allows us to get or set certain properties within a file, including LastWriteTime. We’ll exploit that to achieve what this questioner wants.

Continue reading ‘Retaining The LastWriteTime Value For A File About To Be Overwritten Via FTP / FileUpload By Using ASP.NET’s FileInfo Class’ »