saving files so any user can access them

  • Thread starter Thread starter sklett
  • Start date Start date
S

sklett

I have an application that loads several files from a database (as byte[])
then writes them to the "docs and settings\all users\application data\my
company\my app" folder.

The problem I'm running into is that if I'm logged into windows (domain
admin) and perform actions that result in files being saved they aren't
accessible by other users when the login.
The files that the application saves to disk aren't user specific, they are
application wide. It seems that I need to do something like save the files
with "Guest" privileges. That way anyone can access, modify and delete
them.

Is this the best solution or is there something else I could be doing? I
don't want to use a different location if I don't have to, I would rather
somehow clear the permissions or set a generic permission.

I've found some information on impersonation, but that sounds a little heavy
duty to simply make a file accessible by everyone.

Any suggestions or help greatly appreciated,
Steve
 
Steve,

I can think of two options.

The first is to use isolated storage, getting a file using the machine
store for the application through the static GetMachineStoreForApplication
method on the IsolatedStorageFile class.

The second is to keep the file where it is, but change the permissions
to make sure it is accessible by everyone. Basically, you will have to get
the FileInfo and DirectoryInfo instances for the directory and files,
respectively, and call the GetAccessControl methods on them, getting the
FileSecurity and DirectorySecurity instances from them and modifying the
permissions through those.
 
Nicholas,
Thank you for the reply, that worked perfect!

<code>
FileInfo fileInfo = new FileInfo(path);
FileSecurity fileSecurity = fileInfo.GetAccessControl();
fileSecurity.AddAccessRule(new FileSystemAccessRule(
"Users",
FileSystemRights.FullControl,
AccessControlType.Allow) );

fileInfo.SetAccessControl(fileSecurity);
</code>

Have a good weekend,
Steve


Nicholas Paldino said:
Steve,

I can think of two options.

The first is to use isolated storage, getting a file using the machine
store for the application through the static GetMachineStoreForApplication
method on the IsolatedStorageFile class.

The second is to keep the file where it is, but change the permissions
to make sure it is accessible by everyone. Basically, you will have to
get the FileInfo and DirectoryInfo instances for the directory and files,
respectively, and call the GetAccessControl methods on them, getting the
FileSecurity and DirectorySecurity instances from them and modifying the
permissions through those.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

sklett said:
I have an application that loads several files from a database (as byte[])
then writes them to the "docs and settings\all users\application data\my
company\my app" folder.

The problem I'm running into is that if I'm logged into windows (domain
admin) and perform actions that result in files being saved they aren't
accessible by other users when the login.
The files that the application saves to disk aren't user specific, they
are application wide. It seems that I need to do something like save the
files with "Guest" privileges. That way anyone can access, modify and
delete them.

Is this the best solution or is there something else I could be doing? I
don't want to use a different location if I don't have to, I would rather
somehow clear the permissions or set a generic permission.

I've found some information on impersonation, but that sounds a little
heavy duty to simply make a file accessible by everyone.

Any suggestions or help greatly appreciated,
Steve
 

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

Back
Top