Official comment
Hi Jon,
To upload a file from your file system please follow the instructions below:
- Use "CreateMessage" to upload a Document to Clarizen
- Use "CreateMesage" to link between the new document to a Work Item
Code example:
private void UploadAndLinkFiletoWorkItem(Clarizen clarizenService)
{
var documentId = UploadFile(clarizenService);
LinkFileToWorkItem(documentId, clarizenService);
}
private static EntityId UploadFile(Clarizen clarizenService)
{
var content = File.ReadAllBytes(@"C:\Temp\photo.jpg");
var createMessage = new CreateMessage
{
Entity = new Entity
{
Id = new EntityId { TypeName = "Document" },
Values = new[]
{
new FieldValue {FieldName = "Content", Value = content},
new FieldValue {FieldName = "Name", Value = "photo.jpg"}
}
}
};
var results = clarizenService.Execute(new[] { createMessage });
var createResult = ((CreateResult)results[0]);
return createResult.Id;
}
private static void LinkFileToWorkItem(EntityId documentId, Clarizen clarizenService)
{
var createMessage = new CreateMessage
{
Entity = new Entity
{
Id = new EntityId { TypeName = "AttachmentLink" },
Values = new[]
{
new FieldValue {FieldName = "Document", Value = documentId},
new FieldValue{FieldName = "Entity", Value = new EntityId{TypeName = "Project", Value = "5ra3pfvvxr45m3gyyrr0v97ke5792"}}
}
}
};
var results = clarizenService.Execute(new[] { createMessage });
}
*************************
I hope this helps,
Elad