Skip to content

How to get full path of libaries/Pictures in windows 7

Peter Martin

Asked Sep 11, 2010, 2:55 PM EDT2 answers
Share
LinkedInX
Hi,

Under windows 7, in the windows explorer view there is a new feature called "Libraries" which have virtual links to "Pictures", "documents" etc.. plus you can add your own virtual link.

These libraries are virtual paths.

In either vb.net of c#:


Can anyone please tell me how to get the full physical path of any of the libraries.

The folders name may be "Pictures" or "Downloads", and what I would like to access is the full physical path directory for each defined library.
e.g "Pictues" would be say "C:\Users\me\Pictures"
or "Downloads" would be say "C:\Users\me\Downloads"


I have looked a special folders but I cannot see anything that refers to these new "virtual libraries"


Thanks

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Mike Gold
    0
    You probably need to use the Shell Programming API which is an integral part of Windows 7 for accessing libraries.
    Check out:  http://msdn.microsoft.com/en-us/magazine/dd861346.aspx
     
    You can use the following COM call to get the info you want
    IShellItem *psi; HRESULT hr = SHGetKnownFolderItem(FOLDERID_PicturesLibrary, KF_FLAG_CREATE, NULL, IID_PPV_ARGS(&psi)); if(SUCCEEDED(hr)) { IShellFolder *psf; hr = psi->BindToHandler(NULL, BHID_SFObject | , IID_PPV_ARGS(&psf)); if(SUCCEEDED(hr)) { IEnumIDList *penumIDList; psf->EnumObjects(NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS , IID_PPV_ARGS(&penumIDList)); //use penumIDList to enumerate the content of the folder } }
    If you are using this in C#, you'll need to use PInvoke to bring in the library API.  My guess is it would be easier to write a Visual C++ unmanaged Dll that wraps the above call and returns the path.  Then marshal the wrapped call using dllimport and pinvoke.
    0
  • 0
    I think Libraries is just a way to group. (Not sure). To get specific folder paths to special windows folder for the logged in user
    Environment.SpecialFolder gives u access to most of the special folders. Version 4.0 has more folder paths to the earlier verions
    Console.WriteLine(System.Environment.GetFolderPath(Environment.SpecialFolder.MyMusic));
    Console.WriteLine(System.Environment.GetFolderPath(Environment.SpecialFolder.MyPictures));
     
    http://msdn.microsoft.com/en-us/library/system.environment.specialfolder(v=VS.100).aspx
    0