Search code examples
c#.netfile-iouniqueidentifierntfs

unique information in each file or folder NTFS


im working on a project where in i need to populate some files from the server and show them in a webrowser to the user. Where user would be allowed to do basic CRUD operation on the file The problem is that i cannot assign the name of the file/folder as unique id which i need in case a user deletes/renames a file i should be able to identify the file later.

My question is that is there anything unique about any file/folder in NTFS that is unique about them and that can be used? and how that information can be accessed using .NET c#.

Came across the BY_HANDLE_FILE_INFORMATION structure but it probably needs me to pinvoke.

UPDATE 1 - tried looking at the feasibility to use nFileIndexHigh and nFileIndexLow but they would need me to do a pinvoke and also this method cannot be used with folders one link when they mention folders Unique Folder Identifier tells me that it isnt possible.


Solution

  • Disregarding the fact that it seems that you don't want to P/Invoke a different approach could be to use the Windows Shell API. This API has the concept of a PIDL which identifies a folder (or "similar" item) in the shell namespace. A PIDL does not change even if the user renames the folder. The drawback is that the Shell API exposes what you see in Windows Explorer, e.g. Desktop is at the root of the hierarchy even though it physically is subfolder somewhere on a disk.