I download a file from FTP by pressing a button to a folder on the phone. How to specify this folder?

button.Click += delegate { string inputfilepath = @"/storage/emulated/0/Download/1.txt"; //путь к папке на телефоне string ftpfullpath = "ftp://ххх/ххх/1.txt"; using (WebClient request = new WebClient()) { request.Credentials = new NetworkCredential("login", "password"); byte[] fileData = request.DownloadData(ftpfullpath); using (FileStream file = File.Create(inputfilepath)) //здесь выдает исключение Access to the path "/storage/emulated/0/Download/1.txt" is denied { file.Write(fileData, 0, fileData.Length); file.Close(); } } }; 
  • 1. For such purposes, methods / properties of the environment that you use are commonly used. For example, Android has Android.OS.Environment.DirectoryDownloads , and Xamarin itself has System.Environment . 2. To access such folders, you need permissions (if I’m not mistaken this is READ_EXTERNAL_STORAGE / WRITE_EXTERNAL_STORAGE ), do you have them (judging by Access denied not ...)? - EvgeniyZ 4:27 pm
  • the fact of the matter is, these permissions are connected to me), but about the methods you wrote, maybe you have an example, how can this be done differently using these methods?) - dina_lucky February
  • Here on the official Xamarin forum , people talk about the same problem, maybe they will get it. - EvgeniyZ 4:56 pm
  • Your error is not complete, see what it writes specifically, because now it is just “an error has occurred”. Well, the error itself, this is already a problem in working with the server, and not your initial question about access to the directory. Also, if you have an addition on the issue (your code is from the comment), then you should add everything to the question itself (the "edit" button is in question), because here it is rather inconvenient to read this. Well, in general, if this is already a problem in working with the server, then you probably found the answer to the main question (access to the directory) and it is worth writing it as an answer, and working with the server is another matter to describe. - EvgeniyZ pm
  • thank you very much) created another question) I haven't really figured out with this commenting system yet) - dina_lucky

0