How to create a hardlink in C#?

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

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

5条回答
  •  囚心锁ツ
    2020-12-14 08:04

    The BCL doesn't provide this, so you'll have to resort to p/invoke

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

    And use it e.g. like

     CreateHardLink(@"c:\temp\New Link", @"c:\temp\Original File",IntPtr.Zero);
    

提交回复
热议问题