4

How can I display documents (doc, docx, rtf) in an UWP app? The WebView isn't able to do this.

Other options would be calling an external application with Windows.System.Launcher.LaunchUriAsync (e.g. Word) or using a 3rd party library. The requirement is to have the data in the app, because you don't have control over it, if it's handled to another one. Another option would be to convert it to another format (e.g. PDF) which UWP can handle (not really).

Any ideas?

testing
  • 19,681
  • 50
  • 236
  • 417

2 Answers2

3

If you would like to display word or pdf files in the UWP app you can use WebView control with Google Docs Viewer - I was using it for the online documents.

This is the code:

XAML:

<WebView x:Name="MyWebView"/>

Code behind:

public WebViewPage()
    {
        this.InitializeComponent();
        loadWebView();
    }

    void loadWebView()
    {
        var googleDocsViewer = "http://drive.google.com/viewerng/viewer?embedded=true&url=";
        var pdf = "http://www.uma.es/precarios/images/pdfs/wd-spectools-word-sample-04.doc";
        MyWebView.Navigate(new Uri(googleDocsViewer + pdf));
    }

I did not test it with local files, but I think that should also work. Please try and let me know.

enter image description here

Daniel Krzyczkowski
  • 2,732
  • 2
  • 20
  • 30
  • 1
    The idea is good, but I need a solution, which also works offline. Nevertheless, thanks for your addition. – testing May 18 '16 at 07:54
  • Hi testing, did you get a solution to your issue. I am doing kinda something similar and I could not find any controls for these file formats. I am using a third party control for PDF files but the controls for .docx or .xlsx render open files in MS office itself. Further Daniel , can we use the WebView control for local storage. I went through https://msdn.microsoft.com/en-us/windows/uwp/controls-and-patterns/web-view but the 'Navigate' does not work for a .docx file in app Data local folder. – shagufta syed Aug 02 '16 at 07:28
  • Dear @shaguftasyed unfortunately I do not have solution yet for the local files... I am trying to solve it but non of local file are opened with above link. – Daniel Krzyczkowski Aug 02 '16 at 07:40
  • It helps me somehow, but when will we get a better solution! – Arsman Ahmad Aug 30 '18 at 10:45
0

UWP can actually handle RTF files with RichEditBox - for more info about that see here in the official documentation (I don't know about RichTextBlock). For Docx support I can recommend a third-party library by Syncfusion, which you can get for free if you meet certain requirements.

brullsker
  • 7
  • 4