First sorry for my bad English. The problem I have is when I'm creating a button to filepicker a file in Android folder, but when I wrote:
message.Attachments.Add("here I don't know");
I want to choose the file who was pickfile with button File.
I'm blocked, I have already searched a lot in internet and not found any solution.
XAML:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="AppETF.View.Menu.DetailViews.SignalementEM">
<ContentPage.Content>
<Grid VerticalOptions="FillAndExpand">
<Button Text="Piece jointe" x:Name="fileLabel" Clicked="File" BackgroundColor="White" FontSize="25"/>
<Button Text="Envoyer l'email" Clicked="SendSMTPMail" BackgroundColor="White" FontSize="25"/>
</Grid>
</ContentPage.Content>
Cs :
private async void File(object sender, EventArgs e)
{
var fileData = await CrossFilePicker.Current.PickFile();
if (fileData == null)
return;
byte[] data = fileData.DataArray;
fileLabel.Text = fileData.FileName;
}
public async Task SendSMTPMail(string numero, string heure, string retard, string motif)
{
var message = new MailMessage();
var smtpServer = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
message.From = (new MailAddress("***"));
message.To.Add("***");
message.Subject = ***;
message.Body = ***;
message.Attachments.Add("second probleme here");
smtpServer.Credentials = new NetworkCredential("***", "****");
smtpServer.UseDefaultCredentials = false;
smtpServer.EnableSsl = true;
smtpServer.Send(message);
await DisplayAlert("", "Email Envoyé", "Ok");
}