반응형
폴더 생성 후 권한없다고 뜰때 사용
private void CreateResourceDirectory()
{
DirectorySecurity directorySecurity = new DirectorySecurity();
directorySecurity.SetAccessRuleProtection(true, false);
SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
// 디렉토리에 모든 사용자가 사용할 수 있게 권한 주기
directorySecurity.AddAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.Write |
FileSystemRights.ReadAndExecute | FileSystemRights.WriteAttributes
| FileSystemRights.Delete | FileSystemRights.CreateFiles, InheritanceFlags.ObjectInherit
| InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow));
DirectoryInfo difo = new DirectoryInfo(DirectoryPath); // 원하는 위치에 객체생성
if (difo.Exists == false) // 폴더의 존재유무 확인
{
difo.Create(directorySecurity); // 권한추가한 폴더 생성
difo.Attributes = FileAttributes.Hidden; // 숨김 폴더로 만들기
}
}
private void DeleteResourceDirectory()
{
try // 권한을 줘도 삭제오류 발생시 오류 잡기
{
DirectoryInfo fifo = new DirectoryInfo(DirectoryPath);
fifo.Delete(true);
}
catch (Exception ex)
{
MessageBox.show(ex.Message);
}
}
반응형
'개발언어 > C#' 카테고리의 다른 글
c# 이미지 전송을 위한 byte[]로 변환 메서드 (0) | 2019.07.10 |
---|---|
c# 마우스 드래그로 폼이동하기 (0) | 2019.07.10 |
c# Form에서 ALT+F4 막기 (0) | 2019.07.10 |
c# 웹 서버에 POST 데이터 전송 메서드 (0) | 2019.06.28 |
c# Webclient로 업로드 프로세스 바 만들기 (1) | 2019.06.28 |