PC Review


Reply
Thread Tools Rate Thread

Absolute Reference to Application Data Directory

 
 
=?Utf-8?B?TWF0dGhldyBGcmVkZXJpY2s=?=
Guest
Posts: n/a
 
      3rd Oct 2006
I have an app that stores information in the Application Data directory and
works fine when it's installed on the device. I just reference "\Application
Data\MySpecialDir" and I'm set. However, if the application is installed on
an SD card this reference fails.

How do I address the Application Data directory on the device itself,
absolutely rather than relatively the way "\Application Directory" does?

Thanks in advance for answering what is likely a very basic question.
 
Reply With Quote
 
 
 
 
Peter Foot [MVP]
Guest
Posts: n/a
 
      3rd Oct 2006
In .NETCF v2.0 use
System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
For v1.0 see the EnvironmentEx class in the SDF 1.4 (www.opennetcf.org/sdf/)

Peter

--
Peter Foot
Device Application Development MVP
www.peterfoot.net | www.inthehand.com


"Matthew Frederick" <(E-Mail Removed)> wrote in
message news:46D6E718-2B9E-43EF-9330-(E-Mail Removed)...
>I have an app that stores information in the Application Data directory and
> works fine when it's installed on the device. I just reference
> "\Application
> Data\MySpecialDir" and I'm set. However, if the application is installed
> on
> an SD card this reference fails.
>
> How do I address the Application Data directory on the device itself,
> absolutely rather than relatively the way "\Application Directory" does?
>
> Thanks in advance for answering what is likely a very basic question.



 
Reply With Quote
 
=?Utf-8?B?TWF0dGhldyBGcmVkZXJpY2s=?=
Guest
Posts: n/a
 
      4th Oct 2006
"Peter Foot [MVP]" wrote:

> In .NETCF v2.0 use
> System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
> For v1.0 see the EnvironmentEx class in the SDF 1.4 (www.opennetcf.org/sdf/)


Ah, perfect Peter, thank you very much!
 
Reply With Quote
 
=?Utf-8?B?c21vcXVhcnQ=?=
Guest
Posts: n/a
 
      8th Mar 2007
Hi!

GetFolderPath is the right way.. as long as Application Data folder exists.
Some devices don't have it by default, so it needs to be created. Here comes
my problem..

I would really like to use this nice SpecialFolder enumeration to create
Application Data folder (which has different names in different languages, of
course), but Directory.Create doesn't cooperate (it requires a string).

Do you know how it's supposed to be done (is there any good way)?
Please help!

Adam


 
Reply With Quote
 
Neil Cowburn
Guest
Posts: n/a
 
      9th Mar 2007
Directory.Create(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData))

--
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:82806C6E-4D0C-4F3E-8903-(E-Mail Removed)...
> Hi!
>
> GetFolderPath is the right way.. as long as Application Data folder
> exists.
> Some devices don't have it by default, so it needs to be created. Here
> comes
> my problem..
>
> I would really like to use this nice SpecialFolder enumeration to create
> Application Data folder (which has different names in different languages,
> of
> course), but Directory.Create doesn't cooperate (it requires a string).
>
> Do you know how it's supposed to be done (is there any good way)?
> Please help!
>
> Adam
>
>


 
Reply With Quote
 
=?Utf-8?B?c21vcXVhcnQ=?=
Guest
Posts: n/a
 
      9th Mar 2007

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))
>
> --

 
Reply With Quote
 
Neil Cowburn
Guest
Posts: n/a
 
      9th Mar 2007
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))
>>
>> --


 
Reply With Quote
 
=?Utf-8?B?c21vcXVhcnQ=?=
Guest
Posts: n/a
 
      9th Mar 2007

Thank you very much!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Absolute cell reference will not remain absolute. Mike K Microsoft Excel Worksheet Functions 1 8th Oct 2008 07:12 PM
Reference a dll in a separate web application/directory benliu Microsoft ASP .NET 5 11th Jul 2006 10:37 AM
GET PIVOT Data Absolute Reference Herman Merman Microsoft Excel Worksheet Functions 1 8th Jul 2004 04:04 AM
Absolute reference within a formula not really absolute Fred Microsoft Excel Worksheet Functions 3 1st Jul 2004 06:08 PM
absolute reference while copying data from the pivot table kim Microsoft Excel Worksheet Functions 0 22nd Jul 2003 01:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:23 PM.