Hi,
My requirement is something like this. I am supposed to create a foler and have to check whether it already exists or not. If exists then delete the files from the existing folder and for that I need to check for the permissions(for ASPNET user) to that folder. and when files are deleted set the permissions back to the folder as it had earlier.
Skeleton would be like this-
void DeleteFilesFromFolder()
{
Get the access permissions for ASPNET user
if(!Granted)
{
Give him/her the premission to delete the files from folder
}
Delete the files
Set the permission back to the folder
}
Any idea how to do it in C#
Regards,

Set and Remove access(delete) permissions to a folder.
Daveo__
I am using this code..
string
strFolder = Directory.CreateDirectory("E:\\" + txtFolder.Text).ToString(); ADsSecurityUtilityClass secUtility = new ADsSecurityUtilityClass(); object objSecurity =secUtility.GetSecurityDescriptor(strFolder, (
int)ADS_PATHTYPE_ENUM.ADS_PATH_FILE, (int)ADS_SD_FORMAT_ENUM.ADS_SD_FORMAT_IID); if (null != objSecurity){
IADsSecurityDescriptor sd = (IADsSecurityDescriptor)objSecurity; IADsAccessControlList objControl = (IADsAccessControlList)sd.DiscretionaryAcl; bool bAddToACL = true; IEnumerator enumerator = objControl.GetEnumerator(); while (enumerator.MoveNext()){
IADsAccessControlEntry controlEntry = (IADsAccessControlEntry)enumerator.Current; if (controlEntry.Trustee.IndexOf("ASPNET") != -1){
if (controlEntry.AceType == (int)ADS_ACETYPE_ENUM.ADS_ACETYPE_ACCESS_ALLOWED){
bAddToACL =
false;}
but
object objSecurity =
secUtility.GetSecurityDescriptor(strFolder, (
int)ADS_PATHTYPE_ENUM.ADS_PATH_FILE, (int)ADS_SD_FORMAT_ENUM.ADS_SD_FORMAT_IID);line has got an error stating that "The system cannot find the file specified. (Exception from HRESULT: 0x80070002)":null"
What could be the possible error
Regards,
Deanrm
the most reasonable explanations is variable strFolder doesn't conatain valid path.
and exceptions is thrown somewhere inside secUtility.GetSecurityDescriptor. Take a detailed look there
Hope this helps
Will Sullivan
Take a look at FileIOPermission Class. There are also good examples .
HTH