locked
How to attach a document on note through sdk coding in crm 2013? RRS feed

  • Question

  • HI,

    How to attach a document on note through sdk coding in crm 2013? Kindly tell me each steps.

    Monday, June 16, 2014 3:59 AM

Answers

  • If you are using late bound you need to use Entity class instead of using annotation directly like below

    Entity note = new Entity("annotation");


    Our Website| Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.


    Monday, June 16, 2014 7:12 AM
    Moderator
  • Hi Aamir,

    Following fields should be enough:

    Entity annotation"] = new Entity("annotation");
    annotation["objectid"] =  new EntityReference(entityName, new Guid(entityId));
    annotation["objecttypecode"] = entityName;
    annotation["subject"] = "Text Excel";
    annotation["documentbody"] = Convert.ToBase64String(fileCont);
    annotation["mimetype"] = @"application\ms-excel";
    annotation["notetext"] = "Attaching Excel";
    annotation["filename"] = "YouFileName.xls";

    Make sure to set the entityName and the entityId.


    Admin QuikView Solution for CRM 2013



    Monday, June 16, 2014 7:30 AM

All replies

  • Hello,

    Did you Check this Sample, it has complete code


    Our Website| Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    • Proposed as answer by Anupam Bishui Monday, June 16, 2014 12:00 PM
    Monday, June 16, 2014 4:20 AM
    Moderator
  • Hi Mahender,

    I want to understand each step because I am new in CRM 2013. Please If you guide every instructions I will be thankful to you. I want to know what steps should be follow for attach a document in note through sdk coding.

    Monday, June 16, 2014 4:44 AM
  • Could you provide some information when you want to add this, what is your functional requirement ? maybe then we can help you.

    Our Website| Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Monday, June 16, 2014 4:54 AM
    Moderator
  • HI Mahender,

    Actually  I want to attach a document in note in crm 2013 thorugh asp.net application. scenario is I have a web form When I upldoad a document a click on submit button then document will be attached in note in crm 2013. Please tell me how is it possible ?

    Monday, June 16, 2014 5:32 AM
  • Ok, I am assuming you are going to access your web application in internanet, you can use this code on your button click event, where you need to pass parent record (where you want to attach notes) and service object, and then can host your app in IIS. But if your application is in extranet then you need to make your crm available in extranet or need to implement some communication between your extranet app and intranet crm server.


    Our Website| Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Monday, June 16, 2014 5:42 AM
    Moderator
  • Hi Mahender,

    I will connect web application with crm 2013 through this below code

    ClientCredentials Credentials = new ClientCredentials();


                        Credentials.UserName.UserName = "web.agent";
                        Credentials.UserName.Password = "password";

                        // Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

                        //This URL needs to be updated to match the servername and Organization for the environment. 

                        Uri OrganizationUri = new Uri("http://crmserver:5555/crmLab/XRMServices/2011/Organization.svc");

                        Uri HomeRealmUri = null;

                            string username="";
                            string password="";

                            
    Monday, June 16, 2014 5:47 AM
  • Hi Mahender,

    Here is an image of my web form. When I click upload button then document should be attached in note in crm 2013

    Monday, June 16, 2014 6:15 AM
  • Hi,

    I used FileUpload control in my asp.net page and I have a upload button. I want to save document through this below code but please tell me how can convert file into base64? Please I need help

    annotation note = new annotation();           

               

    note.subject = “Test Export”;

    note.filename = “exported.txt”;

    note.mimetype = “text/html”;

    note.documentbody = b64;

     

    note.objectid = new Lookup();

    note.objectid.type = “new_export”;

    note.objectid.Value = entityid;

    note.objecttypecode = new EntityNameReference();

    note.objecttypecode.Value = “new_export”;

                           

    Guid annotationId = service.Create(note);

    Monday, June 16, 2014 6:44 AM
  • Hi,

    Use this in your upload control button click:

    int fileLen = flupUpload.PostedFile.ContentLength;
    byte[] fileCont = new byte[fileLen];
    flupUpload.PostedFile.InputStream.Read(fileCont, 0, fileLen);
    
    annotation note = new annotation();           
    note.subject = "Test Export";
    note.filename = "exported.txt";
    note.mimetype = "text/html";
    note.documentbody = Convert.ToBase64String(fileCont); //This is where you convert to Base64
    
    note.objectid = new Lookup();
    note.objectid.type = "new_export";
    note.objectid.Value = entityid;
    note.objecttypecode = new EntityNameReference();
    note.objecttypecode.Value = "new_export";
    
    Guid annotationId = service.Create(note);
    

    Change "flupUpload" accordingly as your file upload control name.


    Admin QuikView Solution for CRM 2013

    • Proposed as answer by Anupam Bishui Monday, June 16, 2014 12:00 PM
    Monday, June 16, 2014 7:00 AM
  • Hi Dynamotion,

    Red underline occur in annotation. Please tell me what reference add for resolve this error?

    Monday, June 16, 2014 7:07 AM
  • Hi,

    There are some error occurred. Kindly tell me how to resolve it.

    Monday, June 16, 2014 7:11 AM
  • If you are using late bound you need to use Entity class instead of using annotation directly like below

    Entity note = new Entity("annotation");


    Our Website| Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.


    Monday, June 16, 2014 7:12 AM
    Moderator
  • Hi,

    That's because you're using Early Binding. Try using Late Binding like:

    Entity annotation = new Entity("annotation");
    annotation["subject"] = "Test Export";


    Admin QuikView Solution for CRM 2013

    Monday, June 16, 2014 7:16 AM
  • Hi Dynamotion,

    Do you know that what fields sholud be necessory for save the document?

    Monday, June 16, 2014 7:20 AM
  • Hi Aamir,

    Following fields should be enough:

    Entity annotation"] = new Entity("annotation");
    annotation["objectid"] =  new EntityReference(entityName, new Guid(entityId));
    annotation["objecttypecode"] = entityName;
    annotation["subject"] = "Text Excel";
    annotation["documentbody"] = Convert.ToBase64String(fileCont);
    annotation["mimetype"] = @"application\ms-excel";
    annotation["notetext"] = "Attaching Excel";
    annotation["filename"] = "YouFileName.xls";

    Make sure to set the entityName and the entityId.


    Admin QuikView Solution for CRM 2013



    Monday, June 16, 2014 7:30 AM
  • Hi Dynamotion,

    entityName and entityId?

    HOw to set entityName and entityId? 

    Like I want to attach file on contact entity

    Monday, June 16, 2014 7:39 AM
  • Hi Aamir,

    In that case, the entityName will be "contact" and the entityId will be an existing Contact record Id (based on which record you want your file to be attached to).


    Admin QuikView Solution for CRM 2013

    Monday, June 16, 2014 7:44 AM
  • Hi Dynamotion,

    Is this right way?

     annotation["ObjectId"] = new EntityReference("contact", new Guid("9D4AB36C-3892-E311-93F4-002564C04E9E"));

    Monday, June 16, 2014 7:47 AM
  • Yes, that is right. You might want to change all attributes to lower case like "objectid", "subject", etc.

    Admin QuikView Solution for CRM 2013


    Monday, June 16, 2014 7:52 AM
  • okay thanks Dynamotion :)
    Monday, June 16, 2014 8:08 AM