<DllImport("shell32.dll", SetLastError:= True)>Public FunctionSHGetSpecialFolderLocation(hOwner As IntPtr, _ <MarshalAs(UnmanagedType.I4)>nFolder As CSIDL, _ <MarshalAs(UnmanagedType.Struct)>ByRef ppidl As ITEMIDLIST) As IntegerEnd Function
VB Signature:
Public Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" _ (ByVal prmlngHwndOwner As Long, _ ByVal prmlngFolderID As CSIDL, _ prmtypItemIDList As ITEMIDLIST) As Long
Alternative Managed API:
'In Visual Basic.Net Dim fileP As String fileP =My.Computer.FileSystem.SpecialDirectories.MyDocumentsMsgBox(fileP.ToString)
// In C# after adding a Reference to the Microsoft.VisualBasic.dll
using Microsoft.VisualBasic.Devices;
// and in the Code
Computer c = new Computer();
MessageBox.Show(c.FileSystem.SpecialDirectories.MyDocuments);
//In C#.NET
private const int MAX_PATH = 260;
/// <summary>
/// The main entry point for the application.
/// </summary>
///
[STAThread]
static void Main()
{
IntPtr ptrDirVideo = IntPtr.Zero;
SHGetSpecialFolderLocation(IntPtr.Zero, CSIDL.CSIDL_MYVIDEO, ref ptrDirVideo);
string dirVideo = "";
StringBuilder sbDirVideo = new StringBuilder(MAX_PATH);
if (true == SHGetPathFromIDListW(ptrDirVideo, sbDirVideo))
{
dirVideo = sbDirVideo.ToString();
}
sbDirVideo = null;
Marshal.FreeCoTaskMem(ptrDirVideo);
}