Showing posts with label Directory. Show all posts
Showing posts with label Directory. Show all posts

Friday, February 12, 2010

How to find available users in a machine account using C#.Net?

using System.DirectoryServices;

using (DirectoryEntry root = new DirectoryEntry("WinNT://"+ Environment.MachineName ))
{
foreach (DirectoryEntry child in root.Children)
{
if (child.SchemaClassName == "User")
{
Debug.WriteLine(child.Name);
}
}
}

Wednesday, October 28, 2009

How to filter files from the folder?

foreach (string file in Directory.GetFiles("d:\\dotnetkanna\\PDF", "*.pdf", SearchOption.TopDirectoryOnly))
{
listBox1.Items.Add(file);
}

Tuesday, July 14, 2009

How to set permission to the folder programmatically using C#.Net?

using System.IO;
using System.Security.AccessControl;
using System.Security.Principal;



string dirpath = "G:\\Web\\Kanna";
DirectoryInfo dirinfo = new DirectoryInfo(dirpath);
string users = @"NETWORK SERVICE"; //@"ASPNET" // @"EVERYONE"
if (dirinfo.Exists)
{
DirectorySecurity dirsec = dirinfo.GetAccessControl();
FileSystemAccessRule fsar = new FileSystemAccessRule(new NTAccount(users), FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow);
dirsec.AddAccessRule(fsar);
dirinfo.SetAccessControl(dirsec);
}
 
Feedback Form