Wednesday, May 23, 2007

How to do a folder browsing in C#?

For C++, we all know that "SHBrowseForFolder" can be used to browse folder. For example:

//include Ceshell.lib in the lib
BROWSEINFO bi = { 0 };
bi.lpszTitle = _T("Please select a directory to store pictures!");
LPITEMIDLIST pidl = SHBrowseForFolder ( &bi );
if ( pidl != 0 )
{
CString sPath;
TCHAR* buf = sPath.GetBuffer(MAX_PATH);
SHGetPathFromIDList(pidl, buf); //get a full path

sStatus.Format(_T("%s"),buf );
UpdateData(FALSE);

// free memory used
IMalloc * imalloc = 0;
if ( SUCCEEDED( SHGetMalloc ( &imalloc )) )
{
imalloc->Free ( pidl );
imalloc->Release ( );
}
}

But how to do it in C#? It seems this part is missing?

No comments: