question

Tom-4751 avatar image
0 Votes"
Tom-4751 asked ColeXia-MSFT edited

getting System.IO.DirectoryNotFoundException: 'Could not find a part of the path '/C:\'.' in Xamarin

I am using visual studio 2019 and cannot read the list of files in a directory. I have changed my code to keep it very simple with the same error.
I keep gettin this error: System.IO.DirectoryNotFoundException: 'Could not find a part of the path '/C:\'.' not sure why


Here is the code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using System.IO;

namespace HMSsystem.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class PDFViews : ContentPage
{
public PDFViews()
{
InitializeComponent();
}

     private async void OnPDBBtnClicked(object sender, EventArgs e)
     {
         var Paths = new List<String>();
           
         //string path = "C:\\";


         foreach (string path in Directory.EnumerateFiles("C:\\"))
         {
             Console.WriteLine("IN C DIRECTORY: " + path);
         }

         //DirectoryInfo dir = new DirectoryInfo(path);
         //foreach (FileInfo flInfo in dir.EnumerateFiles("*",SearchOption.AllDirectories))
         //{
         //    String name = flInfo.Name;
         //    long size = flInfo.Length;
         //    DateTime creationTime = flInfo.CreationTime;
         //    Paths.Add(name);
         //}


         //if (Directory.Exists(path))
         //{
         //    foreach (var file1 in System.IO.Directory.GetFiles(path))
         //    {
         //        if (file1 != null)
         //        {
         //            Paths.Add(file1);
         //        }
         //    }
         //}

         await Shell.Current.GoToAsync("//LoginPage");


     }

 }

}
Any help would be appreaciated
Thank You
Tom

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ColeXia-MSFT avatar image
0 Votes"
ColeXia-MSFT answered ColeXia-MSFT edited

Hello,

Welcome to Microsoft Q&A!

The directory path is totally different on each platform .

Android

We access file in Internal Storage and External Storage ,check here .

iOS

The file is stored in sandbox directory , check here .

Refer to https://stackoverflow.com/a/61056422/8187800 .

None of them contains the path "C:\\" , but we can access the path from UWP(desktop application access C disk) .



UWP

Plsease check the usage in this link.

In my test

84679-capture.png


But first we need to enable the permission.



If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



capture.png (11.5 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.