I have the following issues with a bit of my code currently.
I have a folder called FileHandling within my UWP C# project. Within that folder is a class called OpenFileClass.cs
Within the OpenFileClass i have an asynchronous void that allows an openFileDialog to be triggered. The code for that is the following:
public async void OpenFile_ClickAsync(object sender, RoutedEventArgs e)
{
FileOpenPicker openPicker = new FileOpenPicker
{
ViewMode = PickerViewMode.List,
SuggestedStartLocation = PickerLocationId.DocumentsLibrary
};
openPicker.FileTypeFilter.Add(".txt");
openPicker.FileTypeFilter.Add(".csv");
StorageFile file = await openPicker.PickSingleFileAsync();
if (file != null)
{
// Application now has read/write privelages for selected file
}
else
{
// Cancel operation and resume program
}
}
On the MainPage.xaml.cs I am trying to call the function OpenFile_ClickAsync by doing the following:
using BS.FileHandling;
private void OpenFile_Click(object sender, RoutedEventArgs e)
{
OpenFileClass.OpenFile_ClickAsync();
}
There is a control on the AppBarButton which has ClickMode="Press" and "Click=OpenFile_Click" which should trigger the function within MainPage.xaml.cs
Now, im pretty new to this and learning slowly but im pretty sure that the openFileDialog has to be an Asynchronous function. Im just not sure how to then call that through another class?
Am I overlooking something small or am I at completely the wrong end of the stick here?