The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Mit Dateizugriffs-Rechten arbeiten

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
-

Posts: 1524
Nickname: nitronic
Registered: Jul, 2006

Norbert Eder works as a software architect.
Mit Dateizugriffs-Rechten arbeiten Posted: Nov 12, 2006 10:14 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by -.
Original Post: Mit Dateizugriffs-Rechten arbeiten
Feed Title: Norbert Eder - Living .NET
Feed URL: http://feeds.feedburner.com/NorbertEder-Livingnet
Feed Description: Copyright (c)2005, 2006 by Norbert Eder
Latest .NET Buzz Posts
Latest .NET Buzz Posts by -
Latest Posts From Norbert Eder - Living .NET

Advertisement
In einigen F��llen muss mit den Dateizugriffs-Rechten gearbeitet werden. So mmuss die ACL (Access Control List) ausgelesen und angepasst werden. Hier ein Code-Snippet, welches den Umgang mit den entsprechenden Klassen aus dem .NET Framework 2.0 zeigt. Kurze Beschreibungen gibt es als Code-Comment.

// Creating a testfile
Console.WriteLine("Creating XML File");

XmlDocument doc = new XmlDocument();
XmlNode root = doc.CreateElement("root");
doc.AppendChild(root);
doc.Save(@"C:temptest.xml");

Console.WriteLine("Getting FileSecurity");

// Getting Access Control List (ACL) of the file
FileSecurity fSec = File.GetAccessControl(@"C:temptest.xml");

// Get Access Right Type
Type accessRightType = fSec.AccessRightType;
Console.WriteLine("AccessRightType: " + accessRightType.FullName);

// Get Owner of the file
string fileOwner = fSec.GetOwner(typeof(System.Security.Principal.NTAccount)).Value;
Console.WriteLine("Owner: " + fileOwner + System.Environment.NewLine);

// Get Access Rules of the file
AuthorizationRuleCollection authRuleColl =
fSec.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));

// Iterate through all Access Rules
foreach (FileSystemAccessRule rule in authRuleColl)
{
Console.WriteLine("Control Type : " + rule.AccessControlType.ToString());
Console.WriteLine("Identity : " + rule.IdentityReference.Value);
Console.WriteLine("Inheritance Flags: " + rule.InheritanceFlags.ToString());
Console.WriteLine("Is Inherited : " + rule.IsInherited.ToString());
Console.WriteLine("Propagation Flags: " + rule.PropagationFlags.ToString());
Console.WriteLine("File System Right: " + rule.FileSystemRights.ToString());
Console.WriteLine(System.Environment.NewLine);
}

Console.WriteLine("Adding new Rule");

// Adding a new rule to the file's Access Control List
fSec.AddAccessRule(new
System.Security.AccessControl.FileSystemAccessRule(
System.Security.Principal.WindowsIdentity.GetCurrent().Name,
System.Security.AccessControl.FileSystemRights.Read &
System.Security.AccessControl.FileSystemRights.Write,
System.Security.AccessControl.AccessControlType.Allow));

Console.WriteLine("Setting nun FileSecurity");

// Save Access Control List
File.SetAccessControl(@"C:temptest.xml", fSec);

Console.ReadKey(false);

Read: Mit Dateizugriffs-Rechten arbeiten

Topic: MOSS 2007 - Building a public website Previous Topic   Next Topic Topic: Application Templates for Windows SharePoint Services 3.0

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use