?
Solved

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

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

771 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