private void ButtonCsvExportStorageItems_Click(object sender, EventArgs e)
 {
     try
     {
         CsvExport.ExportStorageItems(this);
     }
     catch (Exception ex)
     {
         var messageBox = new AlertDialog.Builder(this);
         messageBox.SetTitle("Fehler aufgetreten!");
         messageBox.SetMessage(ex.Message);
         messageBox.SetPositiveButton("OK", (s, evt) => { });
         messageBox.Create().Show();
     }
 }
        public static void ExportStorageItems(Context context)
        {
            SQLite.SQLiteConnection databaseConnection = Android_Database.Instance.GetConnection();
            if (databaseConnection == null)
            {
                return;
            }

            CsvExport export = new CsvExport();

            export.context            = context;
            export.databaseConnection = databaseConnection;

            var result = export.GetStorageItemsAsCsvString();

            export.WriteToFile("Vue-Lagerbestand.csv", result);
        }
        // Erstellt eine CSV Datei.
        private static void Share(Context context)
        {
            SQLite.SQLiteConnection databaseConnection = Android_Database.Instance.GetConnection();
            if (databaseConnection == null)
            {
                return;
            }

            try
            {
                CsvExport export = new CsvExport();

                StringBuilder header = new StringBuilder();
                header.Append("ArticleId|EANCode|Name|Manufacturer|Category|SubCategory|DurableInfinity|WarnInDays|Size|Unit|Notes|MinQuantity|PrefQuantity|StorageName|Supermarket|Calorie|Price");
                header.AppendLine();
                header.Replace("|", export.trennzeichen);

                StringBuilder data        = new StringBuilder();
                var           articleList = databaseConnection.Query <Article>("SELECT * FROM Article ORDER BY ArticleId");
                foreach (Article article in articleList)
                {
                    StringBuilder row = new StringBuilder();
                    export.AddField(row, article.ArticleId);
                    export.AddField(row, article.EANCode);
                    export.AddField(row, article.Name);
                    export.AddField(row, article.Manufacturer);
                    export.AddField(row, article.Category);
                    export.AddField(row, article.SubCategory);
                    export.AddField(row, article.DurableInfinity);
                    export.AddField(row, article.WarnInDays);
                    export.AddField(row, article.Size);
                    export.AddField(row, article.Unit);
                    export.AddField(row, article.Notes);
                    export.AddField(row, article.MinQuantity);
                    export.AddField(row, article.PrefQuantity);
                    export.AddField(row, article.StorageName);
                    export.AddField(row, article.Supermarket);
                    export.AddField(row, article.Calorie);
                    export.AddField(row, article.Price);

                    data.Append(row);
                    data.AppendLine();
                }

                string destination = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
                destination = Path.Combine(destination, "Article.csv");

                //saving the file into device
                using (var writer = new System.IO.StreamWriter(destination, false))
                {
                    writer.Write(header.ToString());
                    writer.Write(data.ToString());
                }

                Java.IO.File filelocation = new Java.IO.File(destination);
                var          path         = FileProvider.GetUriForFile(context, "de.stryi.exportcsv.fileprovider", filelocation);
                Intent       fileIntent   = new Intent(Intent.ActionSend);
                fileIntent.SetType("text/csv");
                fileIntent.PutExtra(Intent.ExtraSubject, "Vü-Artikel.csv");
                fileIntent.SetFlags(ActivityFlags.NewTask);
                fileIntent.AddFlags(ActivityFlags.GrantReadUriPermission);

                fileIntent.PutExtra(Intent.ExtraStream, path);
                context.StartActivity(Intent.CreateChooser(fileIntent, "CSV Datei senden"));
            }
            catch (Exception e)
            {
                throw e;
            }
        }