How to create a hardlink in C#?

后端 未结 5 1084
无人共我
无人共我 2020-12-14 07:31

How to create a hardlink in C#? Any code snippet, please?

5条回答
  •  温柔的废话
    2020-12-14 08:07

    If you mean the NTFS Hardlinks:

    The following is (an introduction of text on dotnetspark) :

    Unfortunately, neither hard links nor soft links are supported by the .NET Framework. Therefore, you will need to dig into the Windows API to allow your application to consume this feature. You can create a hard link using a single line of code using a simple call to the Win32 function, CreateHardLink(), that resides in the Kernel32.dll library. The definition of this function is as follows:

    BOOL CreateHardLink(
      LPCTSTR lpFileName,
      LPCTSTR lpExistingFileName,
      LPSECURITY_ATTRIBUTES lpSecurityAttributes
    );
    

提交回复
热议问题