You can store a hash of the file before deleting it. To see if it is the same file being uploaded, compare the hash with the previous hash. You can do this with one of the HashAlgorithm classes in System.Cryptography, such as SHA1.
"A cryptographic hash function is a deterministic procedure that takes
an arbitrary block of data and returns a fixed-size bit string, the
(cryptographic) hash value, such that an accidental or intentional
change to the data will change the hash value"
Here is some example code to get you started, assuming the variable stream
is a stream with your file data (you could use FileStream
to open it):
var sha = new System.Security.Cryptography.SHA1Managed();
byte [] hash = sha.ComputeHash(stream);
Now, the variable hash
will contain the hash, a fingerprint of the file contents. Even a small change (such as a single bit) will result in a different hash value, but taking the hash on the same file will always return the same hash.