How to get the actual directory path on windows using .NET?
My need is simple. Given a Windows directory p开发者_如何学Cath 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.
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 :)
精彩评论