Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open files in default program?

I'm writing application using Xamarin.forms and i need to open PDF and Doc documents in Droid and IOS. Is there any crossplatform way to achive this? Maybe any packages?

like image 533
Horosho Avatar asked Jun 06 '17 14:06

Horosho


People also ask

How do I set a default program?

Press Win+X to bring up the Power Tasks Menu and choose 'Control Panel' from the list of options displayed. Once in the Control Panel screen, choose 'Programs'. Then, click on the 'Default Programs' link. The Default Programs screen will request you to choose the program that you would like Windows to use by default.

Can I change the default program which opens a file manually?

Open Windows Explorer, right-click the file type you wish to set, and move to the Open with command. Click the option to Choose default program. At the Open with window, select the app you want to use as the new default. Make sure to check the box to Always use the selected program to open this kind of file.


2 Answers

Now you can use the Launcher class by adding a reference to Xamarin.Essentials in your class.

For opening a file by another application use:

await Launcher.OpenAsync(new OpenFileRequest
{
    File = new ReadOnlyFile(file)
});

Where file is the File or FullPath.

You can find more here: https://docs.microsoft.com/en-us/xamarin/essentials/launcher?tabs=android

like image 113
Ahmed Mansour Avatar answered Sep 22 '22 12:09

Ahmed Mansour


It depends on what type of documents you are taking about. In Xamarin.Forms, you can use

Device.OpenUri(new Uri("filepath or http url"));

If there is an application that can handle the extension, then it will prompt you on which app you wish to use.

If you wanted to view them internally, inside the app, without launching a 3rd party app, then we really need to know what type of documents you are opening. If it's a PDF, then you can look at Display Local PDF File In WebView.

Should it be another type of document, you will need to see if there is a different

like image 32
Adam Avatar answered Sep 24 '22 12:09

Adam