I am creating a workflow activity to download the annotation attachment from a custom entity. Running the workflow throws
System.NullReferenceException: Object reference not set to an instance of an object.
Here is my code:
private static string SaveFile(string fileName, string noteBody)
{
string outputFileName = @"C:\temp\" + fileName;
if (!string.IsNullOrEmpty(noteBody))
{
// Download the attachment in the current execution folder.
byte[] fileContent = Convert.FromBase64String(noteBody);
System.IO.File.WriteAllBytes(outputFileName, fileContent);
}
else
{
throw new InvalidPluginExecutionException("File content is empty or cannot be retrieved");
}
return outputFileName;
}
Debugging it shows that the error is thrown by:
System.IO.File.WriteAllBytes(outputFileName, fileContent);
From Visual Studio I get this exception
Request for permission of type System.Security.Permissions.FileIOPermission
CRM online plugins & workflows must be registered & run in sandbox isolation mode, which is secured & partially trusted in cloud (not Full trust).
Hence you cannot access
C:\temp\in Server from Plugin/workflow code. You will get FileIOPermission exception.Read more