How to create a hardlink in C#?

Swapnil Gupta picture Swapnil Gupta · Aug 2, 2010 · Viewed 14.1k times · Source

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

Answer

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

Usage:

CreateHardLink(newLinkPath,sourcePath, IntPtr.Zero);