Setting folder permissions



Hi,

I am creating a windows service. This service has a filewatcher on it.

When I drop a file, I want to parse the filename then create the directory.
The directory will be in a filestore server so I am passing in a UNC path.
The filestore directory will then also be a virtual directory within an
ASP.NET application, so I need to take those permissions into consideration.

I am having problems setting the permissions. The error is
UnauthorizedAccessException.

Here is my code...

string RootPath =
ConfigurationManager.AppSettings["StorePathRoot"];
string[] Folder = e.Name.Split('_');

if (Folder[0] != string.Empty)
{
RootPath += Folder[0] + "\\";

if (!Directory.Exists(RootPath))
{
Directory.CreateDirectory(RootPath);

DirectoryInfo hInfo = new DirectoryInfo(RootPath);
DirectorySecurity dirSec = hInfo.GetAccessControl();

dirSec.AddAccessRule(new
FileSystemAccessRule(@"david\Everyone", FileSystemRights.Modify,
AccessControlType.Allow));
dirSec.AddAccessRule(new
FileSystemAccessRule(@"david\LOCAL SERVICE", FileSystemRights.Modify,
AccessControlType.Allow));

hInfo.SetAccessControl(dirSec);

}
}

System.IO.File.Move(e.FullPath, RootPath + e.Name);


I set the path in the app.config. This is a UNC path (currently to my pc,
but will go to a network share). As you can see, I am trying to give
"Everyone" permisssion and "LOCAL SERVICE" permission. It is actually
failing on the first one, "Everyone". The directory is being created fine.
In fact, if I didn't have the permission routine, when I copy a file into my
drop folder, it does get moved, though if I copy 2 files into the drop
folder, it stops. (I am copying an xml and a pdf file with the same first
part of the filename, i.e. test_1.xml and test_1.pdf )

Any help appreciated.

Thanks.
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available


.



Relevant Pages

  • Advanced Share Permissions question
    ... I have an application which accesses files on a windows ... 2000 server using a UNC path ( ... Is it possible to configure the permissions on the share ... still be able to access the folder by typing it's URL. ...
    (microsoft.public.win2000.security)
  • Re: Minimum NTFS Permissions - Theres such a thing???
    ... ?2001 Microsoft Corporation. ... HOW TO: Set Minimum NTFS Permissions Required for IIS 5.0 to Work WGID:198 ... " List Folder Contents" ...
    (microsoft.public.inetserver.iis.security)
  • Re: Unable to delete orphaned 1.5 GB System Restore folder
    ... The fact that the tech support is based in India has nothing to do with the ... If so you may want to leave this folder alone. ... down to all children folders because i can set those permissions to ... try deleting from the command line using system by using the AT ...
    (microsoft.public.windowsxp.security_admin)
  • Re: Unable to delete orphaned 1.5 GB System Restore folder
    ... The only computers i fix are my own. ... If so you may want to leave this folder alone. ... it includes all subdirectories with inherited permissions. ... try deleting from the command line using system by using the AT ...
    (microsoft.public.windowsxp.security_admin)
  • RE: no OWA
    ... have the correct permissions was the "inetpub" folder. ... Correct the settings in IIS: ... click to check the "Hide All Microsoft Services" ...
    (microsoft.public.windows.server.sbs)

Loading