Export (0) Print
Expand All

UploadFromBase64DataAnnotation Message

CRM 1.2
banner art

Uploads an attachment to an annotation entity.

The relevant classes are specified in the following table.

Type Class
Request UploadFromBase64DataAnnotationRequest
Response UploadFromBase64DataAnnotationResponse
Entity annotation

Remarks

To perform this action, the caller must have access rights on the entity instance specified in the request class. For a list of required privileges, see UploadFromBase64DataAnnotation Privileges.

Example

The following code example shows how to use the UploadFromBase64DataAnnotation message.

[C#]
// Set up the CRM service.
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Initialize an annotation entity instance.
annotation note = new annotation();
note.filename = "Temp.txt";
note.mimetype="text/plain";
note.notetext="This is a sample note.";
note.subject="Test Note";

// Link the annotation instance to another entity instance.
note.objectid = new Lookup();
// Set the type of the entity.
note.objectid.type = EntityName.lead.ToString(); 
// Set the ID of instance that the note is attached to.
note.objectid.Value = new Guid("6124FF9F-E3FA-DA11-8D1C-000874DE7397");
note.objecttypecode = new EntityNameReference();
// Set the type of the entity.
note.objecttypecode.Value = EntityName.lead.ToString();

// Create the annotation.
Guid annotationId = service.Create(note);

// Open a file and read its contents into a byte array.
FileStream stream = File.OpenRead("temp.txt");
byte[] byteData = new byte[stream.Length];
stream.Read(byteData, 0, byteData.Length);

// Encode the data using base64.
string encodedData = System.Convert.ToBase64String(byteData);

// Create the request object.
UploadFromBase64DataAnnotationRequest upload = new UploadFromBase64DataAnnotationRequest();

// Set the properties of the request object.
upload.AnnotationId = annotationId;
upload.FileName = "temp.txt";
upload.MimeType = "text/plain";
upload.Base64Data = encodedData;

// Execute the request.
UploadFromBase64DataAnnotationResponse uploaded = (UploadFromBase64DataAnnotationResponse) service.Execute(upload);
[Visual Basic .NET]
' Set up the CRM service.
Dim service As New CrmService
service.Credentials = System.Net.CredentialCache.DefaultCredentials

' Initialize an annotation instance.
Dim note As New annotation
note.filename = "Temp.txt"
note.mimetype = "text/plain"
note.notetext = "This is a sample note."
note.subject = "Test Note"

' Link the annotation instance to another entity instance.
note.objectid = New Lookup
' Set the type of the entity.
note.objectid.type = EntityName.lead.ToString() 
' Set the ID of instance that the note is attached to.
note.objectid.Value = New Guid("6124FF9F-E3FA-DA11-8D1C-000874DE7397") 
note.objecttypecode = New EntityNameReference
' Set the type of the entity.
note.objecttypecode.Value = EntityName.lead.ToString() 

' Create the annotation.
Dim annotationId As Guid = service.Create(note)

' Open a file and read its contents into a byte array.
Dim stream As FileStream = File.OpenRead("temp.txt")
Dim byteData(stream.Length) As Byte
stream.Read(byteData, 0, byteData.Length)

' Encode the data using base64.
Dim encodedData As String = System.Convert.ToBase64String(byteData)

' Create the request object.
Dim upload As New UploadFromBase64DataAnnotationRequest

' Set the properties of the request object.
upload.AnnotationId = annotationId
upload.FileName = "temp.txt"
upload.MimeType = "text/plain"
upload.Base64Data = encodedData

' Execute the request.
Dim uploaded As UploadFromBase64DataAnnotationResponse = CType(service.Execute(upload), UploadFromBase64DataAnnotationResponse)

Related Topics

CrmService Messages


© 2007 Microsoft Corporation. All rights reserved.


Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft