Tuesday, November 17, 2009

Create Annotation with File

Here is an example to create Annotation:

annotation n = new annotation();

n.objectid = new Lookup();
//define to which entity
n.objectid.Value = new Guid(EntityId);
attach to specific entity
n.objecttypecode = new EntityNameReference();
n.objecttypecode.Value = EntityType;

//Create
Guid noteID = pService.Create(n);

//open and read file
FileInfo file = new FileInfo(fileP);
FileStream fs = file.OpenRead();
byte[] byteData = new byte[fs.Length];
fs.Read(byteData, 0, byteData.Length);
fs.Close();

string encodedData = System.Convert.ToBase64String(byteData);

//Create the Request Object
UploadFromBase64DataAnnotationRequest upload = new
UploadFromBase64DataAnnotationRequest();

//Set the Request Object's Properties
upload.AnnotationId = noteID;
upload.FileName = file.Name;
upload.MimeType = "text/plain";
upload.Base64Data = encodedData;

//Execute the Request
UploadFromBase64DataAnnotationResponse uploaded =
(UploadFromBase64DataAnnotationResponse)pService.Execute(upload);


Entity contain annotation + file.

enjoy,
Rami Heleg