Sharing Files & Email Attachments with Xamarin.Essentials Preview Features

Avatar

James

In the recent release of Xamarin.Essentials (1.1.0), we introduced several new stable features including detect shake, browser customization, and a plethora of platform helpers. The team has also been working hard on one of the top requested features around files. So to get feedback from developers, we snuck a few preview features into 1.1.0. Including the ability to share a file or add a file as an email attachment! It is extremely easy to get started using these new preview features with just a few lines of code.

Enabling Previews

The Xamarin.Essentials team has adopted one of their favorite features from Xamarin.Forms. The “feature flag” approach that enables developers to try out new features before they are officially released. This is a great addition for developers who want early access because special build installation is not needed. Above all, it allows the team to rapidly work on the API and make feedback-based changes if needed. To enable preview features in Xamarin.Essentials there is a new **ExperimentalFeature** class with a single method on it, **Enable**. This method takes in string arguments that represent the feature to enable. Here we can enable both email attachments and sharing files:

This can be done at any point in the application lifecycle but must be called before using the new APIs.

Email Attachments

This feature enables an app to emails files in email clients on the device. After the feature enabled any file can be emailed. Xamarin.Essentials will automatically detect the file type (MIME), then request the file to be added as an attachment. Every email client is different a may only support specific file extensions or none at all.

Here is a sample of writing text to disk and adding it as an email attachment:

Sharing a File

This feature also enables an app to share files with other applications on the device. Xamarin.Essentials will automatically detect the file type (MIME) while requesting a share. Each platform may only support specific file extensions.

Here is a sample of writing text to disk and sharing it to other apps:

As you can see that the Xamarin.Essentials APIs work really well together for the ability to get file directories, save files to disk, and share them with the world!

Learn More

Be sure to check out all of the great Xamarin.Essentials documentation for full setup guides. Additionally, we have also updated our documentation for both Share and Email with the new preview features. If you have any feedback please open up an issue on the Xamarin.Essentials GitHub repo.

Avatar
James Montemagno

Principal Program Manager, Mobile Developers Tools

Follow James   

2 Comments
Avatar
SERKAN ÇAKMAK 2019-04-16 13:48:17
Thank you James we are proud of you 
Avatar
Wong Wei Loon 2019-05-09 02:45:26
Thank you James, that was greatly appreciated. And just a question, can we use this plugin to share images?