Search code examples
c#.nethardlink

How to create a hardlink in C#?


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


Solution

  • [DllImport("Kernel32.dll", CharSet = CharSet.Unicode )]
      static extern bool CreateHardLink(
      string lpFileName,
      string lpExistingFileName,
      IntPtr lpSecurityAttributes
      );
    

    Usage:

    CreateHardLink(newLinkPath,sourcePath, IntPtr.Zero);