Getting Path To Recycle Bin

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
 
J

Jeff Gaines

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;
 
J

Jeff Gaines

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;
 
A

Andreas Johansson

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.
 
A

Andreas Johansson

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.
 
A

Abby

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
 
A

Abby

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top