Question

How can i add file using ESQ

How can i add file attachment using ESQ. I mean in the process Script task. I have file in url say https://*******/filename.extension

Like 0

Like

1 comments

Please feel free to use the example below. The example demonstrates adding a new file to the attachments for the Order record with "fb3b3bb1-dd75-4ec4-9856-bb6498e57f38" id. Please set the parameter values according to the uploading file. Pay attention that the typeId parameter indicates "File" type. It shouldn't be changed. The files from the Attachments detail are saved in the "SectionNameFile" table in the database. For example, the table for Order section is "OrderFile".

var entitySchemaName = "OrderFile";

var parentColumnName = "Order";

var parentColumnValue = new Guid("fb3b3bb1-dd75-4ec4-9856-bb6498e57f38");

var fileContent = new MemoryStream(new byte[20]);

var size = 2000;

var filename = "test.txt";

var typeId = new Guid("529bc2f8-0ee0-df11-971b-001d60e938c6");

var version = "1";

EntitySchema entitySchema = UserConnection.EntitySchemaManager.GetInstanceByName(entitySchemaName);

Entity entity = entitySchema.CreateEntity(UserConnection);

entity.SetDefColumnValues();

EntitySchemaColumn column = entitySchema.Columns.FindByName(parentColumnName);

entity.SetColumnValue(column.ColumnValueName, parentColumnValue);

entity.SetStreamValue("Data", fileContent);

entity.SetColumnValue("Size", size);

entity.SetColumnValue("Name", filename);

entity.SetColumnValue("TypeId", typeId);

entity.SetColumnValue("Version", version);

entity.Save();

return true;

Show all comments