1

My need is simple. Given a Windows directory path all I want is the actual path. I am sure the terminology is wrong, so I am giving an example.

Given C:\Documents and Settings\All Users the method should display:

  • C:\ProgramData on windows 7
  • C:\Documents and Settings\All Users on windows 2003

This is because on windows 7 C:\Documents and Settings is a junction referencing C:\Users and C:\Users\All Users is yet another junction referencing C:\ProgramData, which is the actual directory.

So, my question is what .NET API lets me do all this?

Thanks.

mark
  • 59,016
  • 79
  • 296
  • 580
  • possible duplicate of [this](http://stackoverflow.com/questions/2240734/c-how-to-retreive-the-target-of-a-junction-or-symlink-with-a-standard-user) or [this](http://stackoverflow.com/questions/4571622/ntfs-junctions-trouble-understanding-the-api) – adrianbanks Feb 23 '11 at 16:16
  • You are right, but only partially. No .NET API is given and although I can try and use P/Invoke, this is not the preferred choice. – mark Feb 23 '11 at 16:27
  • I agree. Apparently the only way is through P/Invoke. Voted to close. – mark Feb 23 '11 at 22:26

1 Answers1

1

Check out this code sample from someone who has figured it out already.

Essentially, you have to use the Win32 function DeviceIoControl via P/Invoke passing the FSCTL_GET_REPARSE_POINT as the dwIoControlCode parameter.

As the guy on CodeProject says...

I find it interesting that the .NET Framework's FileAttributes enumeration includes the value FileAttributes.ReparsePoint but there is no other built-in support for Reparse Points.

There is no "native" .NET API to do this, but bear in mind that much of the framework is just a wrapper around P/Invoke calls anyway, so you shouldn't fear them :)

Jon Grant
  • 11,369
  • 2
  • 37
  • 58