Click here to Skip to main content
11,928,078 members (43,154 online)
Click here to Skip to main content
Add your own
alternative version


29 bookmarked

Vista Directory Links in .NET

, 17 Aug 2007
Rate this:
Please Sign up or sign in to vote.
How to retrieve the target directory from a directory link in Windows Vista


This article is based on the article Manipulating NTFS Junction Points in .NET by Jeff Brown.

In Windows Vista, there are a lot of directory links.
For example: The link C:\Documents and Settings opens the target directory C:\Users.
When I was writing my own directory browser for Windows Vista, I stumbled across these directory links.
How should I retrieve the target directory from such a directory link?
This article describes how.


The NTFS file system saves the link information in a so called "reparse point",
using the REPARSE_GUID_DATA_BUFFER structure (See Platform SDK for details).
To read this "reparse point" out of a directory link, you have to open it as a file,
using the CreateFile function without any special access permissions.
If you have successfully opened the file,
you can read the REPARSE_GUID_DATA_BUFFER structure by calling DeviceIoControl,
and then get the target directory out of it.

Using the Code

Use the ReparsePoint.GetTargetDir method like this:

using System.IO;

String linkDir = "C:\\Documents and Settings";
DirectoryInfo directoryInfo = new DirectoryInfo(linkDir);
// targetDir should be "C:\Users"
String targetDir = ReparsePoint.GetTargetDir(directoryInfo); 
if (targetDir == "")
    // The directory is not a link.
    // The directory is a link.

Source Code

using System;
using System.Text;
using System.IO;
using System.Runtime.InteropServices; // DllImport

namespace MyNameSpace
    class ReparsePoint
#region "DllImports, Constants & Structs"
        private const Int32 INVALID_HANDLE_VALUE = -1;
        private const Int32 OPEN_EXISTING = 3;
        private const Int32 FILE_FLAG_OPEN_REPARSE_POINT = 0x200000;
        private const Int32 FILE_FLAG_BACKUP_SEMANTICS = 0x2000000;
        private const Int32 FSCTL_GET_REPARSE_POINT = 0x900A8;
        /// <span class="code-SummaryComment"><summary>

Points of Interest

It took me a lot of time to find out why Windows Vista always denied me access
to the reparse points of all my directory links.
The reason was that I used the GENERIC_READ constant as dwDesiredAccess
in the CreateFile function, and that would require a higher access permission.
But with a value of 0 (no special access permissions) it works!


This project would not have been possible without the assistance of others in the community.
I consulted the following references while implementing this functionality in .NET:


  • 8/17/2007: Initial post to CodeProject


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Manfred Bittersam
Software Developer
Austria Austria
Manfred Bittersam has been developing industrial software
in C++ (MFC), C# and VB.NET for several years.
He has gone through a lot of changes, in career as well as in private life.
He says he has learned a lot from his mistakes Wink | ;)
Enjoy his free articles!

You may also be interested in...

Comments and Discussions

GeneralException of file acces is denied when get all files from hard disk Pin
Member 455457718-Mar-08 21:12
memberMember 455457718-Mar-08 21:12 
GeneralRe: Exception of file acces is denied when get all files from hard disk Pin
Manfred Bittersam9-Jul-08 10:26
memberManfred Bittersam9-Jul-08 10:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151126.1 | Last Updated 17 Aug 2007
Article Copyright 2007 by Manfred Bittersam
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid