Try this:
const int CSIDL_APPDATA = 0x1a;
[DllImport("coredll",SetLastError=true)]
public static extern bool SHGetSpecialFolderPath(IntPtr hWnd, StringBuilder
lpszPath, int nFolder, bool fCreate);
StringBuilder folderPath = new StringBuilder(260);
bool result = SHGetSpecialFolderPath(IntPtr.Zero, folderPath ,
CSIDL_APPDATA, true);
The last parameter, true, will instruct SHGetSpecialFolderPath to create the
folder if it doesn't already exist.
The .NET Compact Framework uses this same API call through a PAL wrapper
method call System.PInvoke.PAL.Environment_GetSpecialFolder but it sets the
fCreate parameter as false.
--
Neil Cowburn
Principal Partner
OpenNETCF Consulting, LLC.
Managed Code in the Embedded World
http://www.opennetcf.com/
http://www.smartdeviceframework.com/
"smoquart" <(E-Mail Removed)> wrote in message
news:4526848D-D438-4C88-AF27-(E-Mail Removed)...
>
> Thank you for your answer.
> Unfortunately, it's not that simple..
>
> The thing is, that doesn't work if Application Data doesn't exist.
>
> The code you posted throws an InvalidOperationException (in
> System.Environment.GetFolderPath()).
>
> It's simple to reproduce - I call that code after renaming Application
> Data.
>
> I am using .NET CF 2.0 (no SP, if that matters)
>
>
> Neil Cowburn" wrote:
>
>> Directory.Create(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData))
>>
>> --