Problem: Generally while working with files we might get the below errors
Request for the permission of type 'FileIOPermission' failed.
(S)\Classes\FileIOPermission\demand
(S)\Classes\WinAPIServer\fileExists- line 11
(S)\Classes\WinAPIServer\fileExists- line 11
or
Request for the permission of type 'FileIOPermission' failed.
(S)\Classes\FileIOPermission\demand
(S)\Classes\WinAPIServer\deleteFile- line 11
Solution:
Set permissionSet;
FileName fileName = ''Test.Xml";
permissionSet = new Set(Types::Class);
permissionSet.add(new InteropPermission(InteropKind::ClrInterop));
permissionSet.add(new FileIOPermission(fileName , 'rw'));
CodeAccessPermission::assertMultiple(permissionSet);
if (WINAPIServer::fileExists(fileName))
{
if (Box::yesNo(strfmt("Do you want to re-write the file", filename), DialogButton::No))
{
WINAPIServer::deleteFile(filename);
}
else
{
return;
}
}
CodeAccessPermission::revertAssert();
A copy will also require FileIOPermission of 'r' on the source file. A Move will require a permission of 'w' on the source.