C#에서 "삭제할 수 없습니다"라는 파일에 대한 사용 권한을 설정하고 읽기 전용으로 설정하고 싶습니다. 그러나 나는 이것을 어떻게하는지 모른다. 너 나 좀 도와 줄 수있어?C#에서 파일 사용 권한 설정
5
A
답변
7
File.SetAttributes()을 살펴보십시오. 그것을 사용하는 방법에 대한 온라인 예제가 많이 있습니다. 당신은 RemoveAttribute 방법에 복사하는 것을 잊었다
FileAttributes attributes = File.GetAttributes(path);
if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
{
// Show the file.
attributes = RemoveAttribute(attributes, FileAttributes.Hidden);
File.SetAttributes(path, attributes);
Console.WriteLine("The {0} file is no longer hidden.", path);
}
else
{
// Hide the file.
File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden);
Console.WriteLine("The {0} file is now hidden.", path);
}
2
입니다 : : 그 MSDN 페이지에서 촬영
private static FileAttributes RemoveAttribute(FileAttributes attributes, FileAttributes attributesToRemove)
{
return attributes & ~attributesToRemove;
}
0
이 속성에 대해 이것이다. (JB 참조의 대답) 또는 권한 , 즉 읽기/쓰기 액세스 등? 후자의 경우 File.SetAccessControl을 참조하십시오. 은 MSDN에서
:// Get a FileSecurity object that represents the
// current security settings.
FileSecurity fSecurity = File.GetAccessControl(fileName);
// Add the FileSystemAccessRule to the security settings.
fSecurity.AddAccessRule(new FileSystemAccessRule(account, rights, controlType));
// Set the new access settings.
File.SetAccessControl(fileName, fSecurity);
는보다 구체적인 예를 들어 How to grant full permission to a file created by my application for ALL users?를 참조하십시오.
원래 질문에서 FileSystemRights.Delete
을 허용하지 않으려는 것 같습니다.
관련 문제
- 1. Java에서 NTFS 파일 사용 권한 설정
- 2. 파일 권한 설정
- 3. 파일 사용 권한 질문
- 4. IIS 파일 사용 권한
- 5. 파일 사용 권한 확인
- 6. 파일 사용 권한
- 7. WCF 파일 사용 권한?
- 8. 파일 사용 권한 질문
- 9. Vista에서 폴더 사용 권한 설정
- 10. 디렉터리/파일 사용 권한 문제
- 11. Wix - 파일 읽기 권한 설정
- 12. 레이크를 사용하여 파일 권한 설정
- 13. WiX 권한 - 기존 디렉토리에 대한 사용 권한 설정
- 14. Filezilla에서 기본 업로드 파일 권한 설정
- 15. ASP.NET 계정에서 Windows 계정 만들기 및 파일 사용 권한 설정
- 16. Apache 서버 파일 사용 권한
- 17. wsgi + django - 파일 사용 권한
- 18. Subversion 파일 사용 권한 수정
- 19. IIS7 및 파일 사용 권한
- 20. Linux 기본 파일 사용 권한
- 21. asp.net 로그 파일 사용 권한
- 22. iPhone 시뮬레이터의 파일 사용 권한
- 23. Drupal 7의 파일 사용 권한 관련 문제
- 24. 파이썬의 압축 파일에 대한 사용 권한 설정
- 25. C# .NET에서 NTFS 사용 권한 설정
- 26. ASP 3.0 폴더/파일 권한 설정
- 27. PHP 쓰기 파일 및 권한 설정
- 28. C에서 비트 단위 설정
- 29. svn 설정 권한 문제
- 30. MSI 설치 프로그램 파일/폴더 사용 권한