[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2003-12-04
4
Medium Priority
?
1,550 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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.
Integration Management Part 2
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month18 days, 2 hours left to enroll

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