0

We would like to create a small document management system in our C# application. It should be possible to download a file, edit it and then upload it again. The whole thing is represented in a grid like this:

Filename | Checked out by |
FileAbc | userXY23423423 | download | upload
FileDek | userdMd8765655 | download | upload
FileGHI | userhW45389459 | download | upload

Now the downloaded file should be able to be identified when uploading, e. g. with a hash which is stored in the database. This is to make sure that not another file is accidently overwritten.

Use Cases:
-A user can upload a file with <input type="file" name="file" />.
-The File is listed in a grid list like above. -So another User should now be able to download FileAbc, modify it and upload it again. The original file on the server should now be overwritten by the modified uploaded file.

Now our problem is the same as how to find out the original file from a file upload?

  • We tried the creation date of a file first. This will change every time you download the file.

  • Then we found a properties list for files: FileAttributes Enumeration. Unfortunately, we can't write a custom attribute value with a GUID or something like that in it.

  • This makes the only option currently available to store the GUID in the file name. However, we would like to avoid this since the users can get that as strange and delete it during the upload.

My current code is just a common upload/download function like this File Upload. I don't expect any final solution but really appreciate a good hint.

Astrophage
  • 1,231
  • 1
  • 12
  • 38
  • have you tried settings custom properties like - https://stackoverflow.com/questions/19947887/add-new-metadata-properties-to-a-file ? – Kevin Smith Aug 14 '17 at 10:28
  • Thank you. Yes i'd checked that link, too. Unfortunately, it works for NTFS only. – Astrophage Aug 14 '17 at 10:36
  • 1
    You can use hashing to do this. Just calculate hash (sha, md5 or other) and compare to hash of source file. – Kirill Bestemyanov Aug 14 '17 at 10:49
  • 1
    @KirillBestemyanov: "So another User should now be able to download TheFile1.txt, **modify it** and upload it again." - hashing won't work... – Chris Aug 14 '17 at 10:50
  • 1
    @MaxPower: I'm not sure there is a way you can do this with arbitrary files. A text file (as the example you use) has no way to store its change history, author details or anything else. The only way you have to identify a file is, as you said, by filename but if you want it to work with users renaming files then there is no way to do what you want. For example I download a file called "Chris.txt" which contains just "Chris". If I now rename it to "Bob.txt" and change the contenxt to "Bob" then there is no way to differentiate that from a new file with that name and contents. – Chris Aug 14 '17 at 10:53
  • 1
    What you could potentially do is when uploading files you have to either upload it to an existing file (ie a page for that file has an upload button) in which case the user is basically telling you which file it replaces) or if its a new file then they have to specifically say so (eg by going to a create file page). Either way though the tracking can't be done in a foolproof way through the file itself. – Chris Aug 14 '17 at 10:55
  • Thanks a lot. I already expected that's not gonna work that easy. The point with selecting a file to overwrite i agree is a good idea and we are gonna do that. We also wanted to use this in particular to validate the upload against the original source to not overwrite another uninvolved file because of the grid list with multiple entries. – Astrophage Aug 14 '17 at 11:04
  • Ask the user, let the user upload a new version of the file by selecting which file to replace and then uploading it. In the general sense you cannot discover this because the file contents can be completely replaced, rendering it completely different from all existing files. – Lasse V. Karlsen Sep 18 '17 at 07:23
  • If the file has a custom file format and a custom local editor, you could embed a unique ID that identifies the file. – Lasse V. Karlsen Sep 18 '17 at 07:24
  • @Lasse V. Karlsen Thank you for you advises. The user will determine which file to overwrite in the grid-list by clicking on the upload button within the grid. Unfortunately, it can happen that 2 files have the same name. Therefore we wanted to implement an additional check. – Astrophage Sep 18 '17 at 07:28
  • Then you simply cannot use the filename alone to identify the file internally. If you can show a list of files, two of which have the same filename, you should already have something that uniquely identifies the file, such as an ID. – Lasse V. Karlsen Sep 18 '17 at 07:39

1 Answers1

0

I would agree with a solution Chris suggested. As an option you could try to use double extensions for the file, for example, user may try to download file named like 'fileName..extension' (for example report.abch545a.doc). But again, I do not think that from UX point of view this is the best way to specify original file :-) just an option :-)

Igor Gnedysh
  • 144
  • 1
  • 10