by suraj babu malla (3 Submissions)
Category: Files/File Controls/Input/Output
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Fri 19th January 2007
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Find the folder permission of network folders
using System.Collections.Generic;
using System.Text;
using System.IO;
/*
* Author suraj babu malla
* About Find the folder permission of network folders
* created date 19-JAN-2007
* */
namespace sharedCrapps
{
class CheckPermission
{
public enum PermissionType
{
FullAccess,ReadOnly,NoAccess,NoDirectory
}
public static PermissionType getPermission(string directoryPath)
{
PermissionType permission = new PermissionType();
DirectoryInfo directInfo = new DirectoryInfo(directoryPath);
if (!directInfo.Exists)
permission=PermissionType.NoDirectory;
else
{
try
{
directInfo.GetFiles();
try
{
TextWriter twriter = new StreamWriter(directoryPath + "\\~test.tmp");
twriter.WriteLine("test");
twriter.Close();
try
{
FileInfo finfo = new FileInfo(directoryPath + "\\~test.tmp");
if(finfo.Exists)
finfo.Delete();
permission = PermissionType.FullAccess;
}
catch
{
permission = PermissionType.FullAccess;
}
}
catch(Exception)
{
permission = PermissionType.ReadOnly;
}
}
catch (Exception)
{
permission=PermissionType.NoAccess;
}
}
return permission;
}
}
}