Click here to Skip to main content
15,030,781 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I was trying to show the pdf from bytes data in xamarin app. I want to show pdf in webview. i tired with below code:

What I have tried:

docname = myReader["Name"].ToString();
                fileName = myReader["TypeofDocument"].ToString();
                bytes = (byte[])myReader["Data"];
                contentType = myReader["ContentType"].ToString();
                string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                string localFilename = docname;
                 string localPath = Path.Combine(documentsPath, localFilename);               
                    File.WriteAllBytes(localPath, bytes);           

webview.Source = "" + localPath;
Updated 14-Jun-21 4:02am

1 solution

You forgot to tell us what the problem is.

Fortunately, it's pretty obvious: a website cannot access files on the user's device.

You are asking a page hosted on to display a file stored in your local application data folder. That is never going to work.

The Xamarin docs archive has some information about displaying a local PDF file by using a local script:
docs-archive/Recipes/xamarin-forms/Controls/display-pdf at master · xamarin/docs-archive · GitHub[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900