Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

We all know the importance of data in today’s world and we also know most of the data that we come across in our day-to-day life is not very organized. How many time have you received an email that contains an important MS Word document , a MS Excel sheet with important statistics or a Power Point presentation that you need to store in your ERP \ CRM system.

With the Duet Enterprise and Office 2010 suite, now it is possible to build solution that would let you interact with you SAP backend directly from your MS Office products.

For example, I would take the following use case:

Jack receives an email from his colleague which contains an important MS Word document attachment. After reading through the document, Jack feels the need to upload this document against one of the Account that he is handling. We would provide Jack with a way to upload the document directly using

MS Word instead of going to his Duet Enterprise enabled SharePoint site or to his SAP backend.

The solution would be a two-step process. The first step would be deploying the BCS solution (vsto packages) onto the client machine. The second step would be to create and deploy the plugin for MS Word that would read the data to and from the backend.

This demo is based on the CRM Account and Attachment entities that are delivered as part of Duet Enterprise Service Pack 1.


Pre-Requisite for this demo is Duet Enterprise Feature Pack 1.0 Service Pack 1.0.


Step1: Creation and deployment of BCS Solution

Assign the required permissions to the BCS models (CRM Account & Account Attachment) from your central administration as shown below. Please select the sub-set of user as per your requirement.

Here I would allow all the authenticated users to have access to this solution.


Export the models with all the permission and proxy information as shown below.


 We’ll use the BCS Artifact tool to generate the artifacts for both the downloaded models. We’ll use the output from step 4 to create the vsto packages using the BCS Solution Packaging Tool. At the end of this step you will have the vsto package which needs to be deployed on the client machine.

Step2: Creating the MS Word Add-on

With Office 2010 and onward the BCS client is integrated in the Office suite, so as a pre-requisite we need Office 2010 to be present on the client machine.

The code for this sample project can be downloaded from here.

The next step would be to create MS Word 2010 Add-in project as shown below.

(PS: We are using .NET Framework 3.5)

Please add the references as shown in the screenshot below.


Once this is done, we would add a user control to the solution. This would be the pane that the user would see with all the controls in it.



Once this is done, we would add a ribbon control. From here we can pop up or hide our user control.



Now, that we have all the controls to start off with we will proceed with the coding part.

Firstly, let’s add the user control that we add to the collection of TaskPane in MS Word. For this we would add the following code in the “ThisAddIn.cs” file that was created from the template.


        private GetDataUserControl customUserControl;

        public Microsoft.Office.Tools.CustomTaskPane customTaskPane;

        private Microsoft.Office.Tools.CustomTaskPaneCollection





        private void ThisAddIn_Startup(object sender, System.EventArgs e)






        private void Load_Pane_Control()


            customUserControl = new GetDataUserControl();

            customTaskPaneCollection =

     new Microsoft.Office.Tools.CustomTaskPaneCollection(

                this.ItemProvider, this.HostContext,

     "Duet Enterprise Document Uploader", this,

     "Duet Enterprise Document Uploader");

            customTaskPane = customTaskPaneCollection.Add(

     customUserControl, "Duet Enterprise Document Uploader");

            customTaskPane.Width = 310;

            customTaskPane.Visible = false;



Let’s now prepare to show and hide the control pane as per the user’s wish. For this I am adding a button on the ribbon control. On click of this button we will hide or show our task pane.



Once this is in place we will write the following code lines in the Ribbon1.cs file.

private void GetDataButton_Click(object sender, RibbonControlEventArgs e)


            //Open the task pane

            if (Globals.ThisAddIn.customTaskPane.Visible)

                Globals.ThisAddIn.customTaskPane.Visible = false;



                Globals.ThisAddIn.customTaskPane.Visible = true;                             




After this we would check whether the required solutions (vsto packages) are installed or not. The following code line will give the installed version of the solution

                expectedDataSolutionVersion =


Once you find that all the required solutions are present and of the correct version.  We then design our task pane. I would go ahead and add a drop down to show the available object (e.g. CRM Account, CRM Activities etc. In the code attached we are only showcasing CRM Accounts but it can be extended very easily for the other scenarios as well following the same steps.)

Next, we will load all the account that the user has access to.

public DataTable GetAllEntry(BCSDetails bcsObj)
            if ((Entity != null)
                && (lobInstance != null))
                // Get the default filters
                IFilterCollection filters =
                // Execute the FindFiltered method online.
                IEntityInstanceEnumerator enumerator =
                TableData = null;
                TableData = catalog.Helper.CreateDataTable(enumerator);
            return TableData;


Once the user has made all the changes and saves the document,  he can upload the document by clicking on the upload attachment button. The upload function would invoke a create attachment call internally as shown below.

public void UploadAttachment(BCSDetails bcsObj,string AccountId, string Name,string Path)


Identity id;

Globals.ThisAddIn.Application.ActiveDocument.Close( Type.Missing,Type.Missing,Type.Missing);

    if ((Entity != null) && (lobInstance != null)){

      IFieldValueDictionary fieldValueDictionary =  Entity.GetCreatorView(bcsObj.creatorName).GetDefaultValues();

       fieldValueDictionary["AccountID"] = AccountId;

       fieldValueDictionary["DOCUMENTNAME"] =Name;

        fieldValueDictionary["DOCMENT_FILE_DESCRIPTION"] = "This a test upload";

        fieldValueDictionary["DOCUMENTFILETYPEDESCRIPTION"] = "application/msword";

       fieldValueDictionary["DOCUMENTFILENAME"] = Name.Replace(".docx", "") + "_"

+System.DateTime.Now.ToString().Replace("/", "").Replace(":", "").Replace(" ", "")

+ ".docx";

        fieldValueDictionary["DOCUMENTFILESIZE"] = FileLength(Path);

        fieldValueDictionary["BINARYCONTENT"] = ReadFile(Path);

        fieldValueDictionary["DOCUMENT_CREATED_AT"] = System.DateTime.Now.ToString();

         fieldValueDictionary["DOCUMENT_CREATED_BY"] = "UserName";

         fieldValueDictionary["DOCUMENT_LAST_CHANGED_AT"] = System.DateTime.Now.ToString();

          fieldValueDictionary["DOCUMENT_LAST_CHANGED_BY"] = "UserName";

  id = Entity.Create(fieldValueDictionary, lobInstance);




If you want to see all the pieces put together then you can download the code from here.

Following on the same lines we can extend the same example for other object like Contact,  Activities etc.  We can go a step forward and even integrate SAP data with other MS Office suite products like MS Excel, Outlook etc.

In future, I would try to publish pug-ins for other offices products.

A good starting point to refer could be the MSDN sites.

Most of the code pieces used in this demo have been taken from MSDN which talk about outlook add-ins.

Hope this provides a starting pointer for you all to start trying out other combinations.