I am trying to access information under C:\Users\Public\Documents\ which displays as C:\Users\Public\Public Documents\ on explorer. Is there a way to be able to access the DirectoryInfo of a directory under the junction using the pathname displayed in explorer in .NET C#?
Asked
Active
Viewed 453 times
2
-
What problems are you running into? Errors? Exceptions? – Adam Lear Jul 14 '11 at 23:55
-
@Anna: what I believe he means is that if you try to open `C:\Users\Public\Public Documents`, it will just plain not work (since there's no such directory). But if you look at directory name in Windows Explorer, it shows up as "Public Documents" (though the address bar will show "Documents" in edit mode). – Pavel Minaev Jul 15 '11 at 00:22
-
2Explorer actually uses both forms: the address bar will show "Public Documents" in breadcrumbs mode, but if you click (or otherwise focus) it, the textbox will show the correct path, which is "C:\Users\Public\Documents". So for cases where you expect users to copy/paste names, you don't need to do anything. Best be consistent with other Windows applications in that sense. If you try to reinterpret the path, there are many things where it can go wrong - e.g. what if there is a real directory named "Public Documents" there? – Pavel Minaev Jul 15 '11 at 00:23
-
@Anna: When creating a DirectoryInfo using anything under "C:\Users\Public\Public Documents\
" returns false when checking DirectoryInfo.Exists. However, I believe I'll be going the approach that @Pavel suggests as reinterpretation of a user specified link can go wrong as there can be in fact a real directory named Public Documents created. – Daryl Jul 15 '11 at 17:37
1 Answers
0
When/how are you expecting to get a C:\users\public\public documents
path?
If a user goes to copy/paste from Explorer, the C:\users\public\documents
path will be copied into the clipboard. Going through a SaveFileDialog
also produces the valid path.
If you need a way to access Windows 7 libraries, you can give the Windows API Code Pack a go. You can then access "Public Documents as KnownFolders.PublicDocuments
, for example. From what I can see (I've never used it before), there's still no way to reliably turn C:\users\public\public documents
into a DirectoryInfo
, but you might have better luck digging through the docs.

Adam Lear
- 38,111
- 12
- 81
- 101