I’m getting the following exception when uploading a file to Rackspace Cloud Files:
Security Exception
Description: The application attempted to perform an operation not
allowed by the security policy. To
grant this application the required
permission please contact your system
administrator or change the
application’s trust level in the
configuration file.Exception Details: System.Security.SecurityException:
Request for the permission of type
‘System.Security.Permissions.FileIOPermission,
mscorlib, Version=2.0.0.0,
Culture=neutral,
PublicKeyToken=b77a5c561934e089’
failed
It seems to only happen with this file.
It is happening in a method where I check for a unique file name and I can’t seem to figure out why.
private string GetUniqueStorageItemName(string storageItemName)
{
int count = 0;
string Name = "";
if (cloudConnection.GetContainerItemList(Container).Contains(storageItemName))
{
System.IO.FileInfo f = new System.IO.FileInfo(storageItemName); // error on this line
if (!string.IsNullOrEmpty(f.Extension))
{
Name = f.Name.Substring(0, f.Name.LastIndexOf('.'));
}
else
{
Name = f.Name;
}
while (cloudConnection.GetContainerItemList(Container).Contains(storageItemName))
{
count++;
storageItemName = Name + count.ToString() + f.Extension;
}
}
return storageItemName;
}
Working around using FileInfo. Changed the code to the following. Is this the best solution?