Need Help for converting crm 4.0 plugin to crm 2011- Getting error as "The type or namespace ActivityMimeAttachment could not be found"

Unanswered Need Help for converting crm 4.0 plugin to crm 2011- Getting error as "The type or namespace ActivityMimeAttachment could not be found"

  • Thursday, March 01, 2012 11:15 AM
     
     

    Hi all,

    I have a crm 4.0 plugin email attachment, in the link below(i wanted to post whole code but restriction in forum form so i included the link) please have a look

    http://social.microsoft.com/Forums/en/crm/thread/5644fbaf-8243-4af3-915f-0a14ff8b3e9c

    and I converted half of the code in crm 2011, but i am getting some error as "The type or namespace ActivityMimeAttachment could not be found"

    The code is as follows

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.ServiceModel;

     

    using Microsoft.Xrm.Sdk;

    using Microsoft.Xrm.Sdk.Query;

    using Microsoft.Xrm.Sdk.Discovery;

    using Microsoft.Xrm.Sdk.Messages;

    using Microsoft.Xrm.Sdk.Client;

     

    // This namespace is found in Microsoft.Crm.Sdk.Proxy.dll assembly

    // found in the SDK\bin folder.

    using Microsoft.Crm.Sdk.Messages;

     

    namespace Attachement_1

    {

        publicclassAttachmentHandler: IPlugin

        {

     

            IOrganizationServiceserviceProvider;

            decimalMAXATTACHMENTSIZE = 10 * 1000 * 1024;  // Max size in email system

     

            publicvoidExecute(IServiceProviderserviceProvider)

            {

                IPluginExecutionContextcontext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

                // This has to be a Send message

                if(context.MessageName.ToLower() != "send") return;

               

                if(context.InputParameters.Contains("EmailId") && context.InputParameters["EmailId"] isEntity)

                {

                    Guidemailid = (Guid)context.InputParameters["EmailId"];

                    if(context.PreEntityImages.Contains("pre_email"))

                    {

                        //        DynamicEntity entity = (DynamicEntity)context.PreEntityImages.Properties["pre_email"];

                        Entityentity = (Entity)context.PreEntityImages["pre_email"];

                        //if (entity.Properties.Contains("hdm_includeattachments"))

                        if(entity.Attributes.Contains("new_includeattachments"))

                        {

                            //CrmBoolean includeattachments = (CrmBoolean)entity.Properties["hdm_includeattachments"];

                            Booleanincludeattachments = (Boolean)entity.Attributes["new_includeattachments"];

                            if(includeattachments == false) return;

                        }

     

                        elsereturn;

                        // Get regarding object

                        //Lookup regardingobject = (Lookup)entity.Properties["regardingobjectid"];

                        EntityReferenceregardingobject = (EntityReference)entity.Attributes["regardingobjectid"];

     

                        decimaltotalfilesize = 0;

     

                        EntityCollectionattachments = GetAttachments(regardingobject.Id);

                       

                        try

                        {

                            intattachmentNo = 0;

     

                            //foreach (DynamicEntity attachment in attachments.BusinessEntities)

     

                            //ERROR BLOCK

                            foreach (Entity attachment in attachments.Entities)

                            {

                                  activitymimeattachment attach = new activitymimeattachment();

                                  attach.activityid = new Lookup(EntityName.email.ToString(), emailid);

                        

                            }

     

                

     

                    }

                  }

                }

            privateEntityCollectionGetAttachments(Guidid)

            {

                // Retrieve all annotations of type document from hdm_tripreport with id

                try

                {

                    // Objectid

                    ConditionExpressioncond1 = newConditionExpression();

                    cond1.AttributeName = "objectid";

                    cond1.Operator = ConditionOperator.Equal;

                    //cond1.Values = new string[] { id.ToString() };

                    cond1.Values.Add(id.ToString());

                    // Attachments only

                    ConditionExpressioncond3 = newConditionExpression();

                    cond3.AttributeName = "isdocument";

                    cond3.Operator = ConditionOperator.Equal;

                    //cond3.Values = new string[] { "1" };

                    cond3.Values.Add("1");

     

                    // Combine conditions into filter

                    FilterExpressioncontactFilter = newFilterExpression();

                    contactFilter.FilterOperator = LogicalOperator.And;

                    contactFilter.Conditions.Add(cond1);

                    //contactFilter.Conditions.Add(cond2);

                    contactFilter.Conditions.Add(cond3);

     

                    // Determine which columns are returned

                    ColumnSetresultSetColumns = newColumnSet(newstring[] { "filename", "filesize", "mimetype", "documentbody"});

                    QueryExpressionquery = newQueryExpression();

                    query.ColumnSet = resultSetColumns;

                    query.Criteria = contactFilter;

                    query.EntityName = "EmailId";

                   

                    // Return all records.

                    query.Distinct = false;

     

                    RetrieveMultipleRequestretrieve = newRetrieveMultipleRequest();

                    retrieve.Query = query;

                    //retrieve.ReturnDynamicEntities = true;

                    RetrieveMultipleResponseretrieved = (RetrieveMultipleResponse)serviceProvider.Execute(retrieve);

                    returnretrieved.EntityCollection;

                }

                catch(Exceptionex)

                {

                    thrownewInvalidPluginExecutionException("An error occurred in the AttachAttachments (GetAttachments) plugin", ex);

                }

     

            }

            privatevoidwhat(strings)

            {

                thrownewInvalidPluginExecutionException("AttachAttachments "+ s);

            }

        }

    }

    Please help me to resolve this, The error block is in RED Color

    I am getting error as

    "the type or namespace ActivityMimeAttachment could not be found(are you missing a using directive or an assemble reference)"

    in the error block

    Thanks in advance

       


    ***

    Regards

    $hivakumar


    • Edited by Shivakumar B Thursday, March 01, 2012 11:18 AM
    •  

All Replies

  • Thursday, March 01, 2012 5:52 PM
    Moderator
     
      Has Code

    Hello,

    Try to use following code block:

    Entity attach = new Entity("activitymimeattachment");
    attach["activityid"] = new EntityReference("email", emailid);


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter

  • Friday, March 02, 2012 4:49 AM
     
     

    Hi Andrii,

    Thanks for the reply,  but I am not able to attach the document-body, file-name & file size

    foreach (Entity attachment in attachments.Entities)
    {
                                
        Entity attach = new Entity("activitymimeattachment");
        attach["activityid"] = new EntityReference("email", emailid);
                                
        if(attachment.Attributes.Contains("documentbody"))
        {
              attach = attachment.Attributes["documentbody"];
         }
                         
    }


    *** Regards $hivakumar