How to create the ATTACHMENT field in a form in Xamarin Forms?

Asked

Viewed 81 times

1

I have a form being developed in a mobile application, one of the fields will have to capture an attachment. I know how to do in html using the input, so what would be the attribute to do this using Xamarin Forms?

1 answer

1


Xamarin.Forms does not yet provide in your package a component for file selection.

However, there are some implementations (including open source) in this sense, since it is a very common need in applications.

Here are two options:

Remembering that this type of component usually does not offer a visual interface, so its activation must be imperative. For example, in your View you place a button and in the click event (or viewModel command) you trigger the action provided by the component, such as selecting, saving or opening a file.

Ex.:

ICommand command = new Command(async () => 
{
    var fileData = await filePicker.Current.PickFile();
    // A partir daqui você usa o fileData como precisar
});
  • I got it, I did it a little differently so you’re making a mistake on Exceptionhandler, can you tell me why?? public async void anexarArquivo(object sender, EventArgs e)
 {
 try
 {

 FileData filedata = await CrossFilePicker.Current.PickFile();
 
 }
 catch (Exception ex)
 {
 ExceptionHandler.ShowException(ex.Message);
 }
 }

  • @Wpfan what error message?

  • That it doesn’t exist in the current context!

  • That one ExceptionHandler looks like a class of its own or you need to instantiate it or you need to include its namespace reference. I suggest you put a breakpoint in the catch and check which original error message

Browser other questions tagged

You are not signed in. Login or sign up in order to post.