Solved

Change file permission on a Unix file using C# / .NET

Posted on 2003-12-04
4
1,305 Views
Last Modified: 2007-12-19
I am in the process of converting an existing Windows Perl program to C# using Visual Studio .NET.

This is a Windows Application and it will create a text file on a shared UNIX file server. By default it creates the file with RWE permission only to user that invokes the appplication. How can I change the file permission on the file using C# or the .NET framework? That is perform what would be equivalent to "chmod 777" to the UNIX file.

I was able to perform the above in Perl but haven't been able to figure out how to do it on C#.

Thanks.
0
Comment
Question by:khrispy
  • 3
4 Comments
 
LVL 6

Expert Comment

by:martinv
ID: 9900401
How are you doing it in perl (considering the application runs on the Windows box)? With rsh or rexec? Try to do it the same in c#.
0
 

Author Comment

by:khrispy
ID: 9900761
In Perl I used the Win32 Perl extentions to set the file protection as follows:

   $mask = Win32::FileSecurity::MakeMask("FULL");

  %permissions = ('Everyone' => $mask,                                         $group => $mask,
                  $user => $mask);

   Win32::FileSecurity::Set($filepath, \%permissions);


  note "FULL" is equivalent to 'RWE' permission

The above funtion to set file protection was meant for Windows NTFS files but they seemd to work also on the UNIX files

The UNIX system where the files are being created is SAMBA-enabled on our network so the Windows client systems on the same network sees it just as another drive.

Maybe you can show me how to use C#/.Net to set the protection on Windows files (RWE for specified group and/or  'everyone') and maybe the same method will work for the UNIX files.

Thanks
0
 
LVL 6

Accepted Solution

by:
martinv earned 500 total points
ID: 9901002
Hi,
samba-enabled unix server drive is for .NET programs almost the same as normal Windows NTFS drive, so standard windows methods should work.

Please try .NET managed c++ library found here
http://www.codeproject.com/dotnet/NTSecurityNET.asp

It can be also done with System.Management classes.
For more info read following thread:
http://www.dotnet247.com/247reference/msgs/14/73727.aspx
0
 
LVL 6

Expert Comment

by:martinv
ID: 9901172
BTW - another (but probably not optimal) option is uploading the file to the unix server via FTP component which is capable of calling chmod command for setting file permissions directly on the unix server.  I know one, but it's not free.

See http://web.rebex.net/ftp.net/samples.aspx

I think, that there is also some free ones - maybe try to look at www.codeproject.com.
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question