adding permissions to a file  
Author Message
TheSniipe





PostPosted: Visual C# General, adding permissions to a file Top

I have a program that uploads and downloads an excel file to the server. Works great except for 1 snag. Every time a new file gets uploaded the file permissions don't allow me to download it again.

The file needs to add the permissions for Internet Guest Account (SERVER\IUSR_SERVER)) and to allow all.

The only parameter I have is the file location and file name on the server. I know its possible but I'm hoping to get a fairly simple solution to it... I don't suppose there is a method changePermissionsOnNTFSFile(string file_location, string account_name, string input_access)

Thanks.



Visual C#2  
 
 
Michael Letterle





PostPosted: Visual C# General, adding permissions to a file Top

Your best bet is probably to spawn cacls.exe. using Process.Start...

cacls filename.ext /e /g SERVER\IUSER_SERVER:F
calcs filename.exe /e /g Everyone:R



 
 
TheSniipe





PostPosted: Visual C# General, adding permissions to a file Top

private void editFileSecurity(string directory, string fileName)

{

Process myProcess = new Process();

myProcess.StartInfo.WorkingDirectory = directory;

myProcess.StartInfo.FileName = fileName;

}

I need to find a way now to put in your line of code, perhaps somthing like:

myProcess.StartInfo.Arguments = "/C cacls "+directory+"\\"+fileName+"";
myProcess.Start() ;

PS, I suck at using this text editor - sorry tried to make it clear


 
 
Michael Letterle





PostPosted: Visual C# General, adding permissions to a file Top

Well fileName would be the file you want to start, so you'd want to actually use "cmd" for the StartInfo.FileName, you also need to add a "/g" option to the arguments to actually grant the read access to everyone. You'll also want to add "/e" so you edit the permissions instead of overwritting them, so it should look more like this:

private void editFileSecurity(string directory, string fileName)

{

Process myProcess = new Process();

myProcess.StartInfo.WorkingDirectory = directory;

myProcess.StartInfo.FileName = "cmd";

myProcess.StartInfo.Arguments = "/c cacls "+ directory+"\\"+fileName + " /e /g Everyone:R ";

myProcess.Start();

}