ACL Deny Deleting a file, testing puposes.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
How do i get the following code to throw two exceptions, <span style="font-family:Courier New; font-size:x-small
<span style="font-family:Courier New; font-size:x-small <span style="color:#2b91af IOException, and <span style="color:#2b91af UnauthorizedAccessException, when deleting a file?
I am trying to test a delete procedure and its associated exceptions. However, I cannot set the ACL appropiately to cause either exception for
<span style="color:#2b91af FileSystem<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small .DeleteFile. Thank you very much.
<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <font face="Courier New" size="2" color="#0000ff" style="font-family:Courier New; color:#0000ff; font-size:x-small
Const
</font>



<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small NequePorro
<span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small As<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
<span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small String<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
= <span style="font-family:Courier New; color:#a31515; font-size:x-small <span style="font-family:Courier New; color:#a31515; font-size:x-small <span style="font-family:Courier New; color:#a31515; font-size:x-small "Neque porro quisquam est
qui dolorem ipsum quia dolor sit amet, adipisci velit."<br/>




<span style="font-family:Courier New; font-size:x-small
<span style="font-family:Courier New; font-size:x-small
<span style="font-family:Courier New; font-size:x-small
<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small Const<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
tTempFile <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small As<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
<span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small String<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
= <span style="font-family:Courier New; color:#a31515; font-size:x-small <span style="font-family:Courier New; color:#a31515; font-size:x-small <span style="font-family:Courier New; color:#a31515; font-size:x-small "tNequePorro.txt"

<span style="font-family:Courier New; font-size:x-small
<span style="font-family:Courier New; font-size:x-small <font face="Courier New" size="2" style="font-family:Courier New; font-size:x-small

</font>




<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small System.IO.<span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small File<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small .WriteAllText(tTempFile,
NequePorro, System.Text.<span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small Encoding
<span style="font-family:Courier New; font-size:x-small
<span style="font-family:Courier New; font-size:x-small .ASCII)











<span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small Dim<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
uDomain <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small As<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
<span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small String<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
= System.<span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small Environment<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small .UserDomainName<br/>
<span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small Dim<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
uAccount <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small As<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
<span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small String<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
= System.<span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small Environment<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small .UserName<br/>
<span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small Dim<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
UID <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small As<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
<span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small String<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
= uDomain + <span style="font-family:Courier New; color:#a31515; font-size:x-small <span style="font-family:Courier New; color:#a31515; font-size:x-small <span style="font-family:Courier New; color:#a31515; font-size:x-small ""<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small +
uAccount
<span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small Dim<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
rights <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small As<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
<span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small FileSystemRights<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
= <span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small FileSystemRights<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small .Delete<br/>
<span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small Dim<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
Rule <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small As<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
<span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small New<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
<span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small FileSystemAccessRule<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small (UID,
rights, <span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small AccessControlType<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small .Deny)<br/>
<span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small Dim<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
fSecurity <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small As<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
<span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small New<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
<span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small FileSecurity<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small (tTempFile,
<span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small AccessControlSections<span style="font-family:Courier New; font-size:x-small

<span style="font-family:Courier New; font-size:x-small .All)<font face="Courier New" size="2" style="font-family:Courier New; font-size:x-small

fSecurity.AddAccessRule(Rule)<br/>
System.IO.
</font>



<span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small File<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small .SetAccessControl(tTempFile,
fSecurity)
<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small <font face="Courier New" size="2" style="font-family:Courier New; font-size:x-small

</font>

<span style="font-family:Courier New; color:#0000ff; font-size:x-small
<span style="font-family:Courier New; color:#0000ff; font-size:x-small
<span style="font-family:Courier New; color:#0000ff; font-size:x-small Try




<span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small FileSystem<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small .DeleteFile(tTempFile,
<span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small UIOption<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small .OnlyErrorDialogs,
<span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small RecycleOption<font face="Courier New" size="2 <font face="Courier New" size="2 .DeletePermanently)</font></font><font face="Courier New" size="2 <font face="Courier New" size="2


</font></font><span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small Catch<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
exIO <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small As<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
System.IO.<span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small IOException<br/>
<span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small Catch<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
exUac <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small As<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
<span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small <span style="font-family:Courier New; color:#2b91af; font-size:x-small UnauthorizedAccessException<font face="Courier New" size="2 </font><font face="Courier New" size="2 <font face="Courier New" size="2

</font></font><span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small <span style="font-family:Courier New; color:#0000ff; font-size:x-small End<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small
<font face="Courier New" size="2" color="#0000ff <font face="Courier New" size="2" color="#0000ff <font face="Courier New" size="2" color="#0000ff Try</font></font></font>

<span style="font-family:Courier New; font-size:x-small <span style="font-family:Courier New; font-size:x-small

View the full article
 
Back
Top