load xml file from mobile
I want to load an Xml file in a listView and this Xml file is in the phone's download file. the path is correct. but nothing was displayed in the listView .I must have the Microsoft.Maui.Essential library but the installation of this package does not work
.NET MAUI
-
Alessandro Caliaro 4,181 Reputation points
2023-02-27T14:41:44.7066667+00:00 you should post some code...
-
yasmina amroun 10 Reputation points
2023-02-27T19:35:16.5133333+00:00 namespace P_COSMobilV1F { public partial class DetailPage : ContentPage { public DetailPage() { InitializeComponent(); LoadXmlFiles(); } private void LoadXmlFiles() { try { var downloadDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Downloads); var xmlFiles = Directory.GetFiles(downloadDirectory, "P-COS_ScannerSettings_PCMBU4PQDL1_V1.xml"); var xmlFileNames = xmlFiles.Select(f => Path.GetFileName(f)); MyListView.ItemsSource = xmlFileNames; } catch (Exception ex) { Console.WriteLine($"Error: {ex.Message}"); } } private void MyListView_ItemSelected(object sender, SelectedItemChangedEventArgs e) { if (e.SelectedItem != null) { var selectedXmlFileName = e.SelectedItem.ToString(); var downloadDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var xmlFilePath = Path.Combine(downloadDirectory, selectedXmlFileName); var xmlContent = File.ReadAllText(xmlFilePath); var xmlDocument = XDocument.Parse(xmlContent); // Faites quelque chose avec le document XML . } } } }
-
Leon Lu (Shanghai Wicresoft Co,.Ltd.) 72,251 Reputation points • Microsoft Vendor
2023-02-28T06:18:03.93+00:00 Could you share namespace about
Environment.SpecialFolder.Downloads
?Which platform is not working when running code? If it not works in android, can you share your tested android device?
-
yasmina amroun 10 Reputation points
2023-02-28T08:22:16.0533333+00:00 namespace P_COSMobilV1F { public partial class DetailPage : ContentPage { public DetailPage() { InitializeComponent(); LoadXmlFiles(); } private void LoadXmlFiles() { try { var downloadDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Downloads); var xmlFiles = Directory.GetFiles(downloadDirectory, "P-COS_ScannerSettings_PCMBU4PQDL1_V1.xml"); var xmlFileNames = xmlFiles.Select(f => Path.GetFileName(f)); MyListView.ItemsSource = xmlFileNames; } catch (Exception ex) { Console.WriteLine($"Error: {ex.Message}"); } } private void MyListView_ItemSelected(object sender, SelectedItemChangedEventArgs e) { if (e.SelectedItem != null) { var selectedXmlFileName = e.SelectedItem.ToString(); var downloadDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var xmlFilePath = Path.Combine(downloadDirectory, selectedXmlFileName); var xmlContent = File.ReadAllText(xmlFilePath); var xmlDocument = XDocument.Parse(xmlContent); // Faites quelque chose avec le document XML . } } } }
-
Leon Lu (Shanghai Wicresoft Co,.Ltd.) 72,251 Reputation points • Microsoft Vendor
2023-02-28T09:29:30.3666667+00:00 Do you use System.Environment.SpecialFolder Enum, but this Enum do not have
Downloads
value, please share the namespace completely. -
yasmina amroun 10 Reputation points
2023-02-28T10:26:05.58+00:00 yes it's an android platform and i used Environment.SpecialFolder.Downloads, but its not working. Ineed to install Microsoft.Maui.Essential package but it won't install
-
yasmina amroun 10 Reputation points
2023-02-28T10:44:12.57+00:00 I even tried to add the reference in the visualstudio console but it does not work .
-
Leon Lu (Shanghai Wicresoft Co,.Ltd.) 72,251 Reputation points • Microsoft Vendor
2023-03-01T08:29:52.84+00:00 it's an android platform
Which target-framework did you set? If you set the target-framework to android 11 later, you can not access the download folder.
From android native document Manage device storage.
Starting in Android 11, apps that use the scoped storage model can access only their own app-specific cache files
Ineed to install Microsoft.Maui.Essential package but it won't install
Do you want to use these Essentials functions? If so, you install
CommunityToolkit.Maui
nugget package like thisCommunityToolkitMaui Get started document.
Sign in to comment