Word document attachment Preview in Navision 2016

Sachin_Sachin_ Member Posts: 67
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 Member Posts: 417
    I've never seen word embedded in a classic NAV client nor RTC
  • Sachin_Sachin_ Member Posts: 67
    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 Member Posts: 86
    Hi,

    You can try to save it as html file and show in WebPageViewer addin.
  • Sachin_Sachin_ Member Posts: 67
    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 Member Posts: 86
    Webpageviewer Addin is the field of the page, it is embedded in page...
    What Nav version does your customer use?
  • Sachin_Sachin_ Member Posts: 67
    edited 2019-06-12
    Hello @AlexDen My customer is using Navision 2016
  • PatrickGrabensteinerPatrickGrabensteiner Member Posts: 10
    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_ Member Posts: 67
    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 Member Posts: 308
    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
                WordHelper@100000000 : DotNet "'Microsoft.Dynamics.Nav.Integration.Office, Version=14.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.Microsoft.Dynamics.Nav.Integration.Office.Word.WordHelper" RUNONCLIENT;
                WordApplication@100000002 : DotNet "'Microsoft.Office.Interop.Word, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.Microsoft.Office.Interop.Word.ApplicationClass" RUNONCLIENT;
                WordDocument@100000001 : DotNet "'Microsoft.Office.Interop.Word, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.Microsoft.Office.Interop.Word.Document" RUNONCLIENT;
                WordWindow@100000004 : DotNet "'Microsoft.Office.Interop.Word, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.Microsoft.Office.Interop.Word.Window" RUNONCLIENT;
                WordPane@100000005 : DotNet "'Microsoft.Office.Interop.Word, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.Microsoft.Office.Interop.Word.Pane" RUNONCLIENT;
                WordPage@100000006 : DotNet "'Microsoft.Office.Interop.Word, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.Microsoft.Office.Interop.Word.Page" RUNONCLIENT;
                DotArray@100000007 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Array" RUNONCLIENT;
                MemoryStream@100000008 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.MemoryStream" RUNONCLIENT;
                Image@100000009 : DotNet "'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.System.Drawing.Image" RUNONCLIENT;
                ImageFormat@100000010 : DotNet "'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.System.Drawing.Imaging.ImageFormat" RUNONCLIENT;
                ErrorMessage@100000003 : 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_ Member Posts: 67
    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 Member Posts: 308
    You know, NO is also an acceptable answer given to customers. PS. use WordHelper 9.0.0.0 for NAV2016.
  • Sachin_Sachin_ Member Posts: 67
    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 Member Posts: 308
    Check if E: is a Trusted location. Looks like the document is opened in Secured Preview mode.
  • Sachin_Sachin_ Member Posts: 67
    Hello @Duikmeester I have Checked the path it's in Trusted location only.
  • AlexDenAlexDen Member Posts: 86
    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
          FileManagement@1119429000 : Codeunit 419;
          WordDocumentPath@1000 : Text;
          NoDocErr@1001 : TextConst 'DEU=Es wurde kein Beleg angegeben.;ENU=No document has been specified.';
          ServerFileNameHtml@1119429001 : Text;
    
        PROCEDURE SetFileName@1(NewFileName@1119429000 : Text);
        BEGIN
          WordDocumentPath := NewFileName;
        END;
    
        LOCAL PROCEDURE ConvertToHtml@22();
        VAR
          TempBlobHtml@1006 : Record 99008535;
          PdfWriter@1119429000 : DotNet "'Microsoft.Dynamics.Nav.PdfWriter, Version=10.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.Microsoft.Dynamics.Nav.PdfWriter.WordToPdf";
          InStreamWordDoc@1007 : InStream;
          OutStreamHtmlDoc@1008 : OutStream;
          WordFile@1119429002 : File;
          HtmlFile@1119429003 : File;
          ServerFileNameWord@1119429001 : 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 WebPageViewer@-2::ControlAddInReady@8(callbackUrl@1000 : Text);
        BEGIN
          IF ServerFileNameHtml = '' THEN
            ERROR(NoDocErr);
    
          CurrPage.WebPageViewer.SetContent(FileManagement.GetFileContent(ServerFileNameHtml));
        END;
    
        EVENT WebPageViewer@-2::DocumentReady@9();
        BEGIN
        END;
    
        EVENT WebPageViewer@-2::Callback@10(data@1000 : Text);
        BEGIN
        END;
    
        EVENT WebPageViewer@-2::Refresh@11(callbackUrl@1000 : Text);
        BEGIN
          IF ServerFileNameHtml <> '' THEN
            CurrPage.WebPageViewer.SetContent(FileManagement.GetFileContent(ServerFileNameHtml));
        END;
    
        BEGIN
        END.
      }
    }
    
  • krikikriki Member, Moderator Posts: 9,115
    [Topic moved from 'NAV/Navision Classic Client' forum to 'NAV Three Tier' forum]

    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.