Sample code to add attachment by code.

Hi,

I want to add a file attachmewnt to a task by code.

Any hint?

Thanks in Advance,

Omar Zelaya

You can use following code:

var
  WorkIns: TWorkflowInstance;
begin
 
  WorkIns := TWorkflowInstance.Create(nil, WorkflowStudio1);
  try
    WorkIns.Key := <some workflow key>;
    WorkflowStudio.WorkflowManager.LoadWorkflowInstance(WorkIns);
    WorkIns.Diagram.Attachments.AddFile('Attachment','C:\Users\Public\Pictures\Sample Pictures\Koala.jpg');
    WorkflowStudio.WorkflowManager.SaveWorkflowInstance(WorkIns);
  finally
    WorkIns.Free;
  end;

Thanks,

How can I load the attachments by code?

It is possible to get the date when the attachment was created?

Thanks in advance,

Omar Zelaya

Hi again,

How to delete and downloand attachment by code?

Thanks in advance,

Omar Zelaya

You can use the same approach in all operations: you load the workflow instance, work with it, save it (if you need to update it), and that's it.

Thus, to load attachments, just read the WorkIns.Diagram.Attachments collection to list all the attachments.

Each attachment has attachment items

WorkIns.Diagram.Attachments[0].Items

Each item has method SaveContentToFile and property Content you can use to get its content.

To delete an attachment just remove it from the collection and save the workflow instance.

There is no information about when an attachment was created.

Hi,

Thanks. I have noticed that the WAATTACHMENT table has the CREATEDON Field. There is no propterty on the Attachments class to acces it?

Thanks in advance,

Omar Zelaya

No, there isn't.