Skip to content
  • English Deutsch

benjamin-abt.com

Performance is a feature | Cloud - AI - Azure - .NET - Sustainability

  • Home
  • Blog
  • Portfolio
    • Overview
    • Workshops & Training
    • Publications
  • Contact
  • Home
  • Blog
  • Create Symbolic Links on Windows with .NET

Create Symbolic Links on Windows with .NET

Create Symbolic Links on Windows with .NET
February 2, 2023 2 min read BEN ABT
.NET C#

This article was written in 2023. Versions, tools and recommendations may have changed since then. Newer posts are collected under .NET.

Symbolic Links (often abbreviated as symlinks) are a type of file or folder shortcut in Windows that reference another file or folder in the file system, rather than copying its contents. Unlike a normal shortcut, a symlink acts as if it were the original file or folder, so any changes to the symlink will affect the original file and vice versa.

Symlinks can be used to create shortcuts to files or folders that are located on another drive, in another location on the same drive or even on a network location. They can also be used to redirect files or folders to a new location or to create multiple references to the same file or folder.

.NET has no built-in API to create symbolic links on Windows. However, it is possible to create symbolic links on Windows with .NET by using the CreateSymbolicLink method of the Win32 class in the Microsoft.Win32.SafeHandles namespace.

C#
 1using System;
 2using Microsoft.Win32.SafeHandles;
 3using System.Runtime.InteropServices;
 4
 5class Program
 6{
 7    [DllImport("kernel32.dll", SetLastError = true)]
 8    static extern bool CreateSymbolicLink(
 9        string lpSymlinkFileName, string lpTargetFileName, SymbolicLink dwFlags);
10
11    enum SymbolicLink
12    {
13        File = 0,
14        Directory = 1
15    }
16
17    static void Main(string[] args)
18    {
19        string linkPath = @"C:\link";
20        string targetPath = @"C:\target";
21
22        bool linkCreated = CreateSymbolicLink(linkPath, targetPath, SymbolicLink.Directory);
23
24        if (linkCreated)
25        {
26            Console.WriteLine("CreateSymbolicLink succeeded.");
27        }
28        else
29        {
30            int errorCode = Marshal.GetLastWin32Error();
31            Console.WriteLine("CreateSymbolicLink failed with error code: " + errorCode);
32        }
33    }
34}

To map an error code (int) to a useful message, you have to look into the Windows Error Codes table. Windows System Error Codes

Related articles

Managed Identity in .NET: Stop Using Connection Strings

Nov 17, 2026 - 12 min read

Managed Identity in .NET: Stop Using Connection Strings

A credential-bearing connection string makes the first Azure request easy and every later security task harder. The same account key or …

Production Rate Limiting in ASP.NET Core

Nov 3, 2026 - 16 min read

Production Rate Limiting in ASP.NET Core

Most ASP.NET Core rate-limiting examples stop after registering a fixed window. That is enough to demonstrate the middleware, but it is not …

The Big Decimal Bugfix with .NET 11

Nov 2, 2026 - 11 min read

The Big Decimal Bugfix with .NET 11

For more than two decades, (decimal)1.23 returned 1.23m. It looked correct, it passed every test and it was a polite lie.


BEN ABT

BEN ABT

Ben is Chief Engineering Officer and Principal Software Engineer at Medialesson.de, with a strong focus on .NET and Microsoft Azure. In his professional role, he designs and builds highly scalable platforms for hybrid and cloud-based scenarios. He also advises companies and C-levels on migrating to the sovereign cloud.

He runs myCSharp.de, the largest and most active German-speaking C# community forum, actively contributes to both his own and external open-source projects and regularly shares his knowledge through his blog, at community events, conferences and as a writer for technical magazines.

Let's Work Together

Looking for an experienced Platform Architect or Engineer for your next project? Whether it's cloud migration, platform modernization or building new solutions from scratch - I'm here to help you succeed.

New Platforms

Modernization

Training & Consulting

Contact Me
X Facebook LinkedIn WhatsApp
Back Next Blog Post

Open for work!

Contact Me
BEN ABT BEN ABT Software Engineer · Microsoft MVP Passionate about .NET, Azure, performance optimization and sustainable software engineering.

Medialesson GmbH Logo

Microsoft MVP Logo

Recent posts

View all
NuGet Staged Publishing with .NET 11 and GitHub Actions

NuGet Staged Publishing with .NET 11 and GitHub Actions

Nov 18, 2026
Managed Identity in .NET: Stop Using Connection Strings

Managed Identity in .NET: Stop Using Connection Strings

Nov 17, 2026
Automating Microsoft Entra External ID: CIAM Provisioning and Branding

Automating Microsoft Entra External ID: CIAM Provisioning …

Nov 10, 2026
Production Rate Limiting in ASP.NET Core

Production Rate Limiting in ASP.NET Core

Nov 3, 2026
The Big Decimal Bugfix with .NET 11

The Big Decimal Bugfix with .NET 11

Nov 2, 2026

Tags

.NET (197) C# (102) ASP.NET Core (50) Azure (43) DevOps (17) Docker (15) Microsoft (14) Security (14) EF Core (11) Microsoft MVP (11) AI (10) GitHub (10) GitHub Copilot (10) Architecture (9) ASP.NET (9) Synology (9) .NET 11 (8) Raspberry (8) Azure Functions (7) Cloudflare (7)
benjamin-abt.com

About BEN

Benjamin Abt is a Software Engineer, Platform Architect and Microsoft MVP specializing in .NET, Azure, cloud architecture, performance optimization and sustainable software development.

Connect

  • Follow me on GitHub
  • Follow me on LinkedIn
  • Follow me on Mastodon
  • Microsoft MVP profile
  • Follow SchwabenCode on GitHub
  • Follow me on X

Quick Links

  • Portfolio
  • Blog
  • Workshops & Training
  • Publications
  • Get in Touch
  • Sitemap
Open for Work

© Copyright Benjamin Abt & SchwabenCode | 2011 - 2026

Content licensed under CC BY 4.0 unless otherwise noted.

  • Impressum
  • Privacy
  • Contact