Word document attachment Preview in Navision 2016

Sachin_Sachin_ Posts: 67Member
edited 2019-06-12 in NAV Three Tier
Hello all,

I am stuck in a requirement wherein when I click the button which I added in my page that’s in ribbon a preview of the attached word document file should open in Navision 2016 itself instead it is Opening outside in a MS word can u plz suggest some solution
Thanks in advance

Answers

  • TallyHoTallyHo Posts: 282Member
    I've never seen word embedded in a classic NAV client nor RTC
  • Sachin_Sachin_ Posts: 67Member
    edited 2019-06-12
    Hello @TallyHo But my client requirement is like once you click on the ribbon document preview should be in Navision itself now I am getting the attachment in ms word can anyone suggest a solution to get the attachment in navision
    Thanks for the response.
  • AlexDenAlexDen Posts: 39Member
    Hi,

    You can try to save it as html file and show in WebPageViewer addin.
  • Sachin_Sachin_ Posts: 67Member
    edited 2019-06-12
    Hello @AlexDen i cannot do that as my customer wants a word document file only, the attached document should preview in Navision itself
    Thanks for your Response.
  • AlexDenAlexDen Posts: 39Member
    Webpageviewer Addin is the field of the page, it is embedded in page...
    What Nav version does your customer use?
  • Sachin_Sachin_ Posts: 67Member
    edited 2019-06-12
    Hello @AlexDen My customer is using Navision 2016
  • This article is a Little bit old but it Shows how you can use a WinWord Control in .net https://www.codeproject.com/Articles/3582/Word-Control-for-NET

    You could create a Control Add-In which provides a Word Control
  • Sachin_Sachin_ Posts: 67Member
    edited 2019-06-12
    Hello @PatrickGrabensteiner Sorry to tell this But i came across this link and even worked on it but dint get the desired result however thanks for the response.
  • DuikmeesterDuikmeester Hoorn, The NetherlandsPosts: 293Member
    Oké, oké... starting to PM me... below sample works on my machine. Should be compatible with NAV2016, tested in BC15. Only thing is, the image is transparant so display it on a white background.
    OBJECT Codeunit 50000 WordDocumentExportPng
    {
      OBJECT-PROPERTIES
      {
        Date=;
        Time=;
        Version List=;
      }
      PROPERTIES
      {
        OnRun=VAR
                [email protected] : DotNet "'Microsoft.Dynamics.Nav.Integration.Office, Version=14.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.Microsoft.Dynamics.Nav.Integration.Office.Word.WordHelper" RUNONCLIENT;
                [email protected] : DotNet "'Microsoft.Office.Interop.Word, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.Microsoft.Office.Interop.Word.ApplicationClass" RUNONCLIENT;
                [email protected] : DotNet "'Microsoft.Office.Interop.Word, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.Microsoft.Office.Interop.Word.Document" RUNONCLIENT;
                [email protected] : DotNet "'Microsoft.Office.Interop.Word, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.Microsoft.Office.Interop.Word.Window" RUNONCLIENT;
                [email protected] : DotNet "'Microsoft.Office.Interop.Word, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.Microsoft.Office.Interop.Word.Pane" RUNONCLIENT;
                [email protected] : DotNet "'Microsoft.Office.Interop.Word, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.Microsoft.Office.Interop.Word.Page" RUNONCLIENT;
                [email protected] : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Array" RUNONCLIENT;
                [email protected] : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.MemoryStream" RUNONCLIENT;
                [email protected] : DotNet "'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.System.Drawing.Image" RUNONCLIENT;
                [email protected] : DotNet "'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.System.Drawing.Imaging.ImageFormat" RUNONCLIENT;
                [email protected] : Text;
              BEGIN
                WordApplication := WordHelper.GetApplication(ErrorMessage);
                WordDocument := WordHelper.CallOpen(WordApplication,'C:\Temp\Temp.docx',FALSE,TRUE);
                WordDocument.ShowGrammaticalErrors := FALSE;
                WordDocument.ShowRevisions := FALSE;
                WordDocument.ShowSpellingErrors := FALSE;
    
                FOREACH WordWindow IN WordApplication.Windows DO BEGIN
                  FOREACH WordPane IN WordWindow.Panes DO BEGIN
                    FOREACH WordPage IN WordPane.Pages DO BEGIN
                      DotArray := WordPage.EnhMetaFileBits;
                      MemoryStream := MemoryStream.MemoryStream(DotArray);
                      Image := Image.FromStream(MemoryStream);
                      Image.Save('C:\Temp\Temp.png',ImageFormat.Png);
                    END;
                  END;
                END;
    
                CLEAR(Image);
                CLEAR(MemoryStream);
                CLEAR(DotArray);
                CLEAR(WordPage);
                CLEAR(WordPane);
                CLEAR(WordWindow);
                WordHelper.CallClose(WordDocument,FALSE);
                WordHelper.CallQuit(WordApplication,FALSE);
                CLEAR(WordDocument);
                CLEAR(WordApplication);
              END;
    
      }
      CODE
      {
    
        BEGIN
        END.
      }
    }
    
    
  • Sachin_Sachin_ Posts: 67Member
    edited 2019-06-13
    Hello @Duikmeester

    Thanks For the response but i am sorry to tell this i am getting this error as per my understanding this error is coming as My Navision 2016 version doesnt support Dotnet varaiables which you have mentioned and moreover i want to display a preview of attached word document not an image.
    ccz5ngiz32ij.png


  • DuikmeesterDuikmeester Hoorn, The NetherlandsPosts: 293Member
    You know, NO is also an acceptable answer given to customers. PS. use WordHelper 9.0.0.0 for NAV2016.
  • Sachin_Sachin_ Posts: 67Member
    Hello @Duikmeester I used WordHelper version 9.0.0.0 and it worked but i m facing issue in using Panes, Pages,ShowRevisions, EnhMetaFileBits,MemoryStream
    km1bqgg0na8o.png
  • DuikmeesterDuikmeester Hoorn, The NetherlandsPosts: 293Member
    Check if E: is a Trusted location. Looks like the document is opened in Secured Preview mode.
  • Sachin_Sachin_ Posts: 67Member
    Hello @Duikmeester I have Checked the path it's in Trusted location only.
  • AlexDenAlexDen Posts: 39Member
    Here is my version of converting Word to Html, version for Nav2017.
    I used pieces of code from the following standard objects:
    1. Page 2115 Report Viewer
    2. Codeunit 9651 Document Report Mgt. (ConvertToHtml function, I'm not sure that it exists in Nav2016)
    OBJECT Page 50254 Word Viewer
    {
      OBJECT-PROPERTIES
      {
        Date=14.06.19;
        Time=15:30:00;
        Modified=Yes;
        Version List=;
      }
      PROPERTIES
      {
        CaptionML=[DEU=Berichtsviewer;
                   ENU=Report Viewer];
        OnOpenPage=BEGIN
                     IF WordDocumentPath = '' THEN
                       WordDocumentPath := FileManagement.OpenFileDialog('Select file', '',FileManagement.GetToFilterText('','*.docx'));
    
                     IF NOT FileManagement.ClientFileExists(WordDocumentPath) THEN
                       ERROR('File %1 doesn''t exist', WordDocumentPath);
    
                     ConvertToHtml;
                   END;
    
        OnClosePage=BEGIN
                      IF EXISTS(ServerFileNameHtml) THEN
                        IF ERASE(ServerFileNameHtml) THEN;
                    END;
    
      }
      CONTROLS
      {
        { 1   ;    ;Container ;
                    ContainerType=ContentArea }
    
        { 2   ;1   ;Field     ;
                    Name=WebPageViewer;
                    ApplicationArea=#Basic,#Suite;
                    ControlAddIn=[Microsoft.Dynamics.Nav.Client.WebPageViewer;PublicKeyToken=31bf3856ad364e35] }
    
      }
      CODE
      {
        VAR
          [email protected] : Codeunit 419;
          [email protected] : Text;
          [email protected] : TextConst 'DEU=Es wurde kein Beleg angegeben.;ENU=No document has been specified.';
          [email protected] : Text;
    
        PROCEDURE [email protected]([email protected] : Text);
        BEGIN
          WordDocumentPath := NewFileName;
        END;
    
        LOCAL PROCEDURE [email protected]();
        VAR
          [email protected] : Record 99008535;
          [email protected] : DotNet "'Microsoft.Dynamics.Nav.PdfWriter, Version=10.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.Microsoft.Dynamics.Nav.PdfWriter.WordToPdf";
          [email protected] : InStream;
          [email protected] : OutStream;
          [email protected] : File;
          [email protected] : File;
          [email protected] : Text;
        BEGIN
          ServerFileNameWord := FileManagement.UploadFileSilent(WordDocumentPath);
          ServerFileNameHtml := FileManagement.GetFileNameWithoutExtension(ServerFileNameWord) + '.html';
    
          WordFile.OPEN(ServerFileNameWord);
          WordFile.CREATEINSTREAM(InStreamWordDoc);
    
          HtmlFile.CREATE(ServerFileNameHtml);
          HtmlFile.CREATEOUTSTREAM(OutStreamHtmlDoc);
    
          PdfWriter.ConvertToHtml(InStreamWordDoc,OutStreamHtmlDoc);
          HtmlFile.CLOSE;
        END;
    
        EVENT [email protected]::[email protected]([email protected] : Text);
        BEGIN
          IF ServerFileNameHtml = '' THEN
            ERROR(NoDocErr);
    
          CurrPage.WebPageViewer.SetContent(FileManagement.GetFileContent(ServerFileNameHtml));
        END;
    
        EVENT [email protected]::[email protected]();
        BEGIN
        END;
    
        EVENT [email protected]::[email protected]([email protected] : Text);
        BEGIN
        END;
    
        EVENT [email protected]::[email protected]([email protected] : Text);
        BEGIN
          IF ServerFileNameHtml <> '' THEN
            CurrPage.WebPageViewer.SetContent(FileManagement.GetFileContent(ServerFileNameHtml));
        END;
    
        BEGIN
        END.
      }
    }
    
  • krikikriki Posts: 8,768Member, Moderator
    [Topic moved from 'NAV/Navision Classic Client' forum to 'NAV Three Tier' forum]

    Regards,Alain Krikilion
    Use the SEARCH,Luke! || No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
    NAV TechDays 2019: 21 & 22 November 2019, Antwerp (Belgium)
Sign In or Register to comment.