Jobs
Author: suraj babu malla Date Submitted: 1/19/2007 Category: File Manipulation Compatibility: .NET This code has been accessed 3485 times.
Email Yourself this snippet:
Find the folder permission of network folders
Code
using System; 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; } } }