Export (0) Print
Expand All

UploadFromBase64DataActivityMimeAttachment Message

CRM 1.2
banner art

Uploads an attachment to an activity mime attachment entity.

The relevant classes are specified in the following table.

Type Class
Request UploadFromBase64DataActivityMimeAttachmentRequest
Response UploadFromBase64DataActivityMimeAttachmentResponse
Entity activitymimeattachment

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 UploadFromBase64DataActivityMimeAttachment Privileges.

Example

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

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

//Initialize an activitymimeattachment object.
activitymimeattachment attachment = new activitymimeattachment();
attachment.attachmentnumber = new CrmNumber();
attachment.attachmentnumber.Value = 1;
attachment.filename="temp.txt";
attachment.mimetype="text/plain";
attachment.subject="Test Attachment";

//Link the attachment to the ID of an activity.
attachment.activityid = new Lookup();
//Set the type of the activity.
attachment.activityid.type = EntityName.email.ToString(); 
//Set the ID of the activity being attached to.
attachment.activityid.Value = new Guid("67FF2B5B-6F22-DB11-A208-000874DE7397"); 

//Create the attachment.
Guid attachmentId = service.Create(attachment);

// 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.
UploadFromBase64DataActivityMimeAttachmentRequest upload = new UploadFromBase64DataActivityMimeAttachmentRequest();

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

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

' Initialize a new activity attachment.
Dim attachment As New activitymimeattachment
attachment.attachmentnumber = New CrmNumber
attachment.attachmentnumber.Value = 1
attachment.mimetype = "text/plain"
attachment.filename = "temp.txt"
attachment.subject = "Test Attachment"

' Link the attachment to the ID of an activity.
attachment.activityid = New Lookup
' Set the type of activity.
attachment.activityid.type = EntityName.email.ToString()
' Set the ID of the activity being attached to.
attachment.activityid.Value = New Guid("67FF2B5B-6F22-DB11-A208-000874DE7397") 

' Create the attachment.
Dim attachmentId As Guid = service.Create(attachment)

' 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 UploadFromBase64DataActivityMimeAttachmentRequest

' Set the properties of the request object.
' AttachmentId is the object id of the activity being attached to.
upload.ActivityMimeAttachmentId = attachmentId
upload.FileName = "temp.txt"
upload.MimeType = "text/plain"
upload.Base64Data = encodedData

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

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