none
VSTO 2013/2016 Word add-in: Save opened document as attachment (in Annotation) to CRM 365 RRS feed

  • Question

  • Hi,

    I have a Word 2013/2016 VSTO Add-in were I want to be able to save the opened word document as a attachment (to a assocated Annotation) in Dynamics 365.

    I already have the context and connection to CRM set up. I have testet that I can save the annotation, but I also need to save the word-document as an attachment (as word-format)

    Do anybody have a example on this?

    regards,

    Marius H. Enerud

    Thursday, March 2, 2017 2:44 PM

All replies

  • Hi morris80,

    generally we use saveas method to save word document.

    Document.SaveAs Method

    void SaveAs(
    	ref Object FileName,
    	ref Object FileFormat,
    	ref Object LockComments,
    	ref Object Password,
    	ref Object AddToRecentFiles,
    	ref Object WritePassword,
    	ref Object ReadOnlyRecommended,
    	ref Object EmbedTrueTypeFonts,
    	ref Object SaveNativePictureFormat,
    	ref Object SaveFormsData,
    	ref Object SaveAsAOCELetter,
    	ref Object Encoding,
    	ref Object InsertLineBreaks,
    	ref Object AllowSubstitutions,
    	ref Object LineEnding,
    	ref Object AddBiDiMarks
    )
    

    but I don't know how Office is connected with Dynamics365.

    currently there is no any documentation available for this requirement.

    This forum supports MS Office related issues, so we have documentation related it but here we don't support for Dynamics 365. so we don't have any details regarding this issue.

    you can try to contact Dynamics 365 support may able to solve your issue.

    Regards

    Deepak 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, March 3, 2017 5:28 AM
    Moderator
  • I need to Get the array of bytes/byte stream of the opened document. That should be enough. But how do I do that?
    Friday, March 3, 2017 6:22 AM
  • Hi morris80,

    I try to consult some senior engineer and try to know their suggestions for this issue.

    they informed me that it is not possible to stream the opened document.

    because currently that document is on RAM and there are some unsaved changes are there.

    they suggest me to save and close the file first and then upload the whole file can be the solution for your issue.

    also they informed me that this issue is not just limited to VSTO because VSTO only provide facility to Automate the documents with the help of code.

    also they suggest me to look for an api if provided by the Dynamics 365.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, March 3, 2017 7:49 AM
    Moderator
  • Thanks for the answer, Deepak!

    I landed on a solution:

    I saved the generated word-document ("SaveAs") without any dialog,  closed it and then read the bytes:

    This worked very well and word-attachment were saved. But I have one more question:

    I need to have the Guid for the entity and the name of the organization, to be able to save to correct Account. Is it possible to store this information in the "Custom XML Part" (so that is can read it in c#-code in the add-in)? I don't want to have this data on the document itself.

    regards,

    Marius H. Enerud

    Tuesday, March 7, 2017 9:49 PM
  • Hi morris80,

    you can do something like below.

     private void AddCustomXmlPartToDocument()
            {
                string xmlString =
                    "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
                    "<employees xmlns=\"http://schemas.microsoft.com/vsto/samples\">" +
                        "<employee>" +
                            "<name>Karina Leal</name>" +
                            "<hireDate>1999-04-01</hireDate>" +
                            "<title>Manager</title>" +
                        "</employee>" +
                    "</employees>";

                Office.CustomXMLPart employeeXMLPart = this.CustomXMLParts.Add(xmlString, missing);
            }

    for more details please visit link below.

    How to: Add Custom XML Parts to Document-Level Customizations

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, March 8, 2017 8:28 AM
    Moderator
  • Deepak, I need to add this xml-data to the document from the CRM-side (the word-document are generated by templates residing in CRM on-prem). The add-in doesn't know the data and should only be able to read out the xml-data.
    I haven't find any solution for this yes. I guess there are no plugins registered on creation of a document?

    regards,

    Marius H. Enerud

    Thursday, March 9, 2017 11:44 AM
  • Hi morris80,

    I can see that you want to add this xml from CRM side.

    but the issue is that we don't support for this CRM.

    We don't know that how it works and interact with Word document.

    we only have the information regarding VSTO.

    so it's out of our scope.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, March 14, 2017 9:46 AM
    Moderator