Solved

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

Posted on 2003-12-04
4
1,381 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

742 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