public static async Task <bool> DownloadFile(FileDetailsViewModel file) { try { //Send a response to try and download the file HttpResponseMessage resp = clientFiles.Download(new Guid(file.Id)); byte[] bytes = resp.Content.ReadAsByteArrayAsync().Result; string localPath = System.IO.Path.Combine(Common.Instance.DocumentFilePath, file.Name); // var imagePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); //var imagePath1 = System.IO.Path.Combine(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures).ToString(), "MyFolderName"); FileStream wFile = new FileStream(localPath, FileMode.Create); wFile.Write(bytes, 0, bytes.Length); wFile.Close(); return(true); } catch (Exception ex) { return(false); } }
public static async Task <bool> DownloadFile(FileItemClient fileItem, Guid fileID) { try { //Retrieve the FileItem to use properties FileItem file = fileItem.Get(fileID); //Send a response to try and download the file HttpResponseMessage resp = fileItem.Download(file.Id.Value); byte[] bytes = resp.Content.ReadAsByteArrayAsync().Result; string localPath = System.IO.Path.Combine(Common.Instance.DocumentFilePath, file.FileName.ToString()); FileStream wFile = new FileStream(localPath, FileMode.Create); wFile.Write(bytes, 0, bytes.Length); wFile.Close(); return(true); } catch (Exception ex) { return(false); } }