How to share the created files like .txt, .vcf etc in Xamarin forms

I am working on Xamarin.Forms application for Android and iOS, I have a requirement to send/share the vCard like sharing a contact in Whatsapp, email, any other sharing apps.
So I am using PCLStorage library for creating the files like .vcf, .txt

Now I want share the created files accordingly, So I have implemented the Share functionality using Dependent Service like below code
But the file is not able to picking for share

So kindly provide the way how to overcome from this

Android Code:

async void Share (string filepath)
{
var intent = new Intent (Intent.ActionSend);
intent.SetType ("text/vcard");

intent.PutExtra (Intent.ExtraStream, Android.Net.Uri.FromFile (path));

var intentChooser = Intent.CreateChooser (intent, "Share vCard");

Forms.Context.StartActivityForResult (intentChooser);
}

iOS Code:

async void Share (string filepath)
{

var item = NSObject.FromObject (filepath);
var activityItems = new[] { item }; 
var activityController = new UIActivityViewController (activityItems, null);

var topController = UIApplication.SharedApplication.KeyWindow.RootViewController;

while (topController.PresentedViewController != null) {
   topController = topController.PresentedViewController;
}

topController.PresentViewController (activityController, true, () => {});

}

Posts

  • Gandhi_123Gandhi_123 Member ✭✭

    Hello @Ganesh.4229

    I want to share contacts which are stored in my mobile local storage. Please tell me how would i generate .vcf file of each data and which plugin i have to use for share this .vcf file.

Sign In or Register to comment.