Getting Path To Recycle Bin

  • Thread starter Thread starter Abby
  • Start date Start date
A

Abby

Hi,

How do you get the path to the Recycle Bin? The code

int CSIDL_BITBUCKET = 0x000a;
int MAX_PATH = 255;
StringBuilder Folderpath = new StringBuilder(MAX_PATH + 1);
uint cc = SHGetSpecialFolderLocation(IntPtr.Zero, 0x001a, Folderpath);

returns garbage while

uint SHGFP_TYPE_CURRENT = 0;
uint cc = SHGetFolderPath(IntPtr.Zero, History, IntPtr.Zero,
SHGFP_TYPE_CURRENT, Folderpath);

returns "invalid arguments."

I once saw a very convoluted method that was supposed to work but I can't
find it again. The paths are temporarily hard coded in for Vista and XP
defaults but that is not a good solution.

Thanks,
Gary
 
Hi,

How do you get the path to the Recycle Bin? The code

int CSIDL_BITBUCKET = 0x000a;
int MAX_PATH = 255;
StringBuilder Folderpath = new StringBuilder(MAX_PATH + 1);
uint cc = SHGetSpecialFolderLocation(IntPtr.Zero, 0x001a, Folderpath);

returns garbage while

uint SHGFP_TYPE_CURRENT = 0;
uint cc = SHGetFolderPath(IntPtr.Zero, History, IntPtr.Zero, SHGFP_TYPE_CURRENT, Folderpath);

returns "invalid arguments."

I once saw a very convoluted method that was supposed to work but I can't
find it again. The paths are temporarily hard coded in for Vista and XP
defaults but that is not a good solution.

Thanks,
Gary

I use:

public static string SpecialFolderPath(CSIDL specialFolder)
{
int dwFlags = 0;
IntPtr ipSpecialFolder = IntPtr.Zero;
StringBuilder pszPath = new StringBuilder((int)JConst.MAX_PATH);
int apiResult = JDll.SHGetFolderPath(IntPtr.Zero, (int)specialFolder,
IntPtr.Zero, dwFlags, pszPath);
return pszPath.ToString();
}

SHGetFolderPath prototype:

// SHGetFolderPath
[DllImport("shell32.dll", EntryPoint = "SHGetFolderPath", SetLastError =
true, CharSet = CharSet.Auto)]
public static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder,
IntPtr hToken, int dwFlags, StringBuilder pszPath);

And CSIDL (from an enum):
CSIDL_BITBUCKET = 0x000a;
 
Hi,

How do you get the path to the Recycle Bin? The code

int CSIDL_BITBUCKET = 0x000a;
int MAX_PATH = 255;
StringBuilder Folderpath = new StringBuilder(MAX_PATH + 1);
uint cc = SHGetSpecialFolderLocation(IntPtr.Zero, 0x001a, Folderpath);

returns garbage while

uint SHGFP_TYPE_CURRENT = 0;
uint cc = SHGetFolderPath(IntPtr.Zero, History, IntPtr.Zero, SHGFP_TYPE_CURRENT, Folderpath);

returns "invalid arguments."

I once saw a very convoluted method that was supposed to work but I can't
find it again. The paths are temporarily hard coded in for Vista and XP
defaults but that is not a good solution.

Thanks,
Gary

I use:

public static string SpecialFolderPath(CSIDL specialFolder)
{
int dwFlags = 0;
IntPtr ipSpecialFolder = IntPtr.Zero;
StringBuilder pszPath = new StringBuilder((int)JConst.MAX_PATH);
int apiResult = JDll.SHGetFolderPath(IntPtr.Zero, (int)specialFolder,
IntPtr.Zero, dwFlags, pszPath);
return pszPath.ToString();
}

SHGetFolderPath prototype:

// SHGetFolderPath
[DllImport("shell32.dll", EntryPoint = "SHGetFolderPath", SetLastError =
true, CharSet = CharSet.Auto)]
public static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder,
IntPtr hToken, int dwFlags, StringBuilder pszPath);

And CSIDL (from an enum):
CSIDL_BITBUCKET = 0x000a;
 
Check out pinvoke.net about SHGetSpecialFolderPath and code samples
http://pinvoke.net/search.aspx?search=SHGetSpecialFolderPath&namespace=[All]

Your first code snippet has two bugs. SHGetSpecialFolderLocation does not
fill a string buffer but return a LPITEMIDLIST pointer. This is why you see
garbage, the call succeeded. You hardcode the CSIDL for APPDATA instead of
using the BITBUCKET value.

Your second snippet call SHGetFolderPath and not SHGetSpecialFolderPath as
it should.
 
Check out pinvoke.net about SHGetSpecialFolderPath and code samples
http://pinvoke.net/search.aspx?search=SHGetSpecialFolderPath&namespace=[All]

Your first code snippet has two bugs. SHGetSpecialFolderLocation does not
fill a string buffer but return a LPITEMIDLIST pointer. This is why you see
garbage, the call succeeded. You hardcode the CSIDL for APPDATA instead of
using the BITBUCKET value.

Your second snippet call SHGetFolderPath and not SHGetSpecialFolderPath as
it should.
 
Andreas Johansson said:
Your first code snippet has two bugs. SHGetSpecialFolderLocation does not
fill a string buffer but return a LPITEMIDLIST pointer. This is why you
see

I discovered this after posting. All found C# examples, including the other
respondent's, did it that way. I found a C++ example on CodeProject but
translating it to C# might be beyond my patience, particularly the pointers
in the requisite structures.
garbage, the call succeeded. You hardcode the CSIDL for APPDATA instead of
using the BITBUCKET value.

Your are right. I created a nmeumonic correctly then hardcoded a wrong
value.

Thanks,
Gary
 
Andreas Johansson said:
Your first code snippet has two bugs. SHGetSpecialFolderLocation does not
fill a string buffer but return a LPITEMIDLIST pointer. This is why you
see

I discovered this after posting. All found C# examples, including the other
respondent's, did it that way. I found a C++ example on CodeProject but
translating it to C# might be beyond my patience, particularly the pointers
in the requisite structures.
garbage, the call succeeded. You hardcode the CSIDL for APPDATA instead of
using the BITBUCKET value.

Your are right. I created a nmeumonic correctly then hardcoded a wrong
value.

Thanks,
Gary
 
Back
Top