안녕하세요 기본적으로 내 % appdata % 폴더를 삭제할 수있는 응용 프로그램에서 단추를 만들려고하지만 읽는 유일한 파일을 삭제할 수 없다는 문제가있어서 인터넷 검색을하기로 결정했습니다. 그러나 문제는 여전히 어쨌든 계속됩니다. 나의 최근 시도는 어떤 단서도 아직 작동하지 않았습니까?C# 읽기 전용 파일 삭제
삭제하려는 것은 % appdata %/test이며 하위 폴더도 있습니다.
private void ClearButton_OnClick(object sender, RoutedEventArgs e)
{
string filepath = (Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "test"));
//Get Currently Applied Access Control
FileSecurity fileS = File.GetAccessControl(filepath);
//Update it, Grant Current User Full Control
SecurityIdentifier cu = WindowsIdentity.GetCurrent().User;
fileS.SetOwner(cu);
fileS.SetAccessRule(new FileSystemAccessRule(cu, FileSystemRights.FullControl, AccessControlType.Allow));
//Update the Access Control on the File
File.SetAccessControl(filepath, fileS);
//Delete the file
File.Delete(filepath);
Process.Start(Application.ResourceAssembly.Location);
Environment.Exit(0);
}
이 방법의 결과는 무엇입니까? –
[읽기 전용 파일을 삭제하는 방법은 무엇입니까?] (http://stackoverflow.com/questions/265896/how-do-i-delete-a-read-only-file) – Cyral
@commusoft http : //i.imgur.com/wdBeCH3.png – MrRdy2Lose