I want to get path of opened file with FileOpenPicker in my UWP application. I have a OpenFile named method. OpenFile methods code:
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.Desktop;
openPicker.FileTypeFilter.Add(".txt");
StorageFile storageFile = await openPicker.PickSingleFileAsync();
if (storageFile != null)
{
var stream = await storageFile.OpenAsync(FileAccessMode.ReadWrite);
using (StreamReader sReader = new StreamReader(stream.AsStream()))
{
Document.Text = sReader.ReadToEnd();
Document.IsSaved = true;
}
}
What do I need to do get file path.
CodePudding user response:
storageFile.Path
will give you the path to the file, if it has one (which it should in this case).
See https://learn.microsoft.com/uwp/api/windows.storage.storagefile.path