Loading a file into a context variable

To upload a file from disk to a context variable (in our example, the context.Report variable is of the Arrachment type) use the following scripts.

Script without PublicAPI.

Add the following namespaces:
using EleWise.ELMA.Files;
using EleWise.ELMA.Runtime.Managers;
using EleWise.ELMA.Services;
using EleWise.ELMA.Common.Managers;
using EleWise.ELMA.Model.Services;
Script text:
context.Report = (Attachment)AttachmentManager.Instance.Create();
context.Report.File = InterfaceActivator.Create<BinaryFile>();
context.Report.File.Name = "test.xlsx";
context.Report.File.CreateDate = DateTime.Now;
context.Report.File.InitializeContentFilePath();   
System.IO.File.Copy("d:\\test.xlsx", context.Report.File.ContentFilePath);
Locator.GetServiceNotNull<IFileManager>().SaveFile(context.Report.File);//save the file to the context
 
Creating a similar script with PublicAPI
Updated documentation on PublicAPI is available here.

Namespaces:

using EleWise.ELMA.Files;

Script text:

context.Report = PublicAPI.Portal.Objects.Common.Attachment.Create();
context.Report.File = InterfaceActivator.Create<BinaryFile>();
context.Report.File.Name = "test.xlsx";
context.Report.File.CreateDate = DateTime.Now;
context.Report.File.InitializeContentFilePath();
System.IO.File.Copy("d:\\test.xlsx", context.Report.File.ContentFilePath);
var attachment = PublicAPI.Portal.Objects.Common.Attachment.Create(context.Report.File);
PublicAPI.Services.File.SaveFile(context.Report.File);