where is appropriate location for data files

G

Gregory K

My C# application creates data files which must be visible to the other users
on this computer. Where is appropriate location for those files? I can always
create my own folder off the root but it doesn't look right. I would like to
use a system folder that will be available in all versions of Windows (XP,
Vista, 7).

I looked at Environment.GetFolderPath() but could not find anything
suitable. SpecialFolder.CommonApplicationData returns hidden folder and
therefore is not good. SpecialFolder.MyDocuments returns the location
available only to the current user.

Can you suggest a .Net command that returns an appropriate location?
 
S

Scott M.

I would imagine you'd put them in a /data folder stemming from your
applicaiton's installation directory.

-Scott
 
R

Roger Frost

Hi Gregory,

I'm fairly certain that you will want to use a location from the
Environment.SpecialFolder enumeration as this will provide the most
consistence across XP, Vista, Windows 7, and future releases.

The question is now which of the 23 available will best suite your needs.

CommonApplicationData resolves to Documents and Settings\All
Users\Application Data (on XP) so I can understand your reservation about
using this location. However, it is the best location suited for your needs
(shared data files) within the enum.

No matter which location you choose, you will want to append
"\\application_name" as a subfolder to it. And in my programs I default the
OpenFileDialog and SaveFileDialog locations to this for user convenience.
Another convenience feature you may consider is having a link to open it in
a new explorer on your application's menu bar, as well as in the start menu
group.

A tempting choice would be to use ProgramFiles or Programs +
"\\application_name", however this location should be reserved for the
binary files of the application and any user-independent configuration
files.

One final option is to allow the user during setup to select the "Shared
Data Folder" location themselves, just be sure to explain that this location
needs to be accessible to other users as well...this will allow them to
select a network share if they choose. And in a network environment,
probably the most desireable choice yet.

If it were me, I would use CommonApplicationData \ application_name with
some convenience features to allow easy browsing.

To each his own, and I hope this helps.

Regards,
Roger

"Logic Is Syntax Independent"
 
A

Alberto Poblacion

Scott M. said:
I would imagine you'd put them in a /data folder stemming from your
applicaiton's installation directory.

Only if the data is read-only. The various users of the computer should
not have write access to the application installation directory.

For a discussions of various locations that you might want to use for
your data depending on the circumstances, take a look at this article:
http://blogs.msdn.com/cjacks/archiv...te-program-data-instead-of-program-files.aspx
 
G

Gregory K

CommonApplicationData resolves to Documents and Settings\All
Users\Application Data (on XP) so I can understand your reservation about
using this location.

I am afraid you don't. "Application Data" is a hidden folder (in XP), so
simple minded user will never see it in the browser. This is not acceptable.
One final option is to allow the user during setup to select the "Shared
Data Folder" location themselves.

That was the main purpose of my post - how can I get the path to shared data
at runtime? The problem is that it is different in XP, Vista and Windows 7
and I could not find a system command that returns this path. I was hoping
someone would suggest it.

Gregory
 
H

henry.lee.jr

Hi Gregory,

I'm fairly certain that you will want to use a location from the
Environment.SpecialFolder enumeration as this will provide the most
consistence across XP, Vista, Windows 7, and future releases.

The question is now which of the 23 available will best suite your needs.

CommonApplicationData resolves to Documents and Settings\All
Users\Application Data (on XP) so I can understand your reservation about
using this location.  However, it is the best location suited for your needs
(shared data files) within the enum.

No matter which location you choose, you will want to append
"\\application_name" as a subfolder to it.  And in my programs I default the
OpenFileDialog and SaveFileDialog locations to this for user convenience.
Another convenience feature you may consider is having a link to open it in
a new explorer on your application's menu bar, as well as in the start menu
group.

A tempting choice would be to use ProgramFiles or Programs +
"\\application_name", however this location should be reserved for the
binary files of the application and any user-independent configuration
files.

One final option is to allow the user during setup to select the "Shared
Data Folder" location themselves, just be sure to explain that this location
needs to be accessible to other users as well...this will allow them to
select a network share if they choose. And in a network environment,
probably the most desireable choice yet.

If it were me, I would use CommonApplicationData \ application_name with
some convenience features to allow easy browsing.

To each his own, and I hope this helps.

Regards,
Roger

"Logic Is Syntax Independent"

--------------------------------------------------
From: "Gregory K" <[email protected]>
Sent: Wednesday, September 02, 2009 8:50 AM
Newsgroups: microsoft.public.dotnet.languages.csharp
Subject: where is appropriate location for data files

Thank you for reminding me of another reason why for GUI-driven
applications, I always try to go ASP.NET before resorting to a Windows
form :)
 
R

Roger Frost

Gregory K said:
I am afraid you don't. "Application Data" is a hidden folder (in XP), so
simple minded user will never see it in the browser. This is not
acceptable.

Hence the added "convenience" features, if you open the folder in the
Explorer it WILL display it's contents that isn't hidden (and the ones that
are depending on Folder Options) based on the current user's credentials,
but you can control the flags during IO, very easily I might add.

Generally speaking, raw data that is shared among and between users should
be in CommonApplicationData (as opposed to any other location in the
SpecialFolder enumeration), or a shared network folder. The reason for this
is, and you are correct "it is different in XP, Vista and Windows 7", but
believe it or not grasshopper, using CommonApplicationData improves the
portability of your program.

Your other logical option is in the root drive but as you pointed out, it's
not healthy to use it. You can also consider a thumb drive for maximum
portability!!!

You don't need to agree with me, but I encourage you to consider all
implications of your decision. Also, my posts come with a full money back
guarantee equal to the amount originally charged by me and paid by you for
the information, so you my friend will be receiving a refund of all money
you have paid to me so far, and therefore you are out of nothing for reading
my advice.

May I ask why you would want to grant users (let alone encourage) direct
access to raw data files in the first place?

Sometimes the problem isn't really the problem :)

-Roger
 
P

Peter Duniho

I am afraid you don't. "Application Data" is a hidden folder (in XP), so
simple minded user will never see it in the browser. This is not
acceptable.

You may want to reconsider making this data stored in a specific location
then. Putting the question back in the user's hands, making them manually
specify a location for the data may be more appropriate.

That said, there is in fact a "shared" directory you can use. On XP, this
is called "Shared Documents", under the "All Users" path. It appears to
me that, for some reason, .NET doesn't include this in the
Environment.SpecialFolders enumeration. But you can still get the current
path value using the unmanaged Win32 API via p/invoke.

See "CSIDL_COMMON_DOCUMENTS" on
http://msdn.microsoft.com/en-us/library/bb762494(VS.85).aspx

Note also the comment at the top of that page, describing the newer
Vista-and-later API. You should use the newer API unless you specifically
need to support XP (and of course, most people today still will have to :)
).

Pete
 

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