Пример #1
0
 public bool TryDownload(ShareFileMetadata shareFile, out byte[] fileData)
 {
     try
     {
         fileData = DownloadAsync(shareFile).GetAwaiter().GetResult();
         return(true);
     }
     catch (Exception e)
     {
         DownloadException = new FileshareDownloadException($"The file '{shareFile.Name}{shareFile.Extension}' could not be downloaded", e);
         fileData          = null !;
         return(false);
     }
 }
Пример #2
0
        public async Task <byte[]> DownloadAsync(ShareFileMetadata shareFile)
        {
            var directory = _shareClient.GetDirectoryClient(shareFile.GetEncodedDirectoryPath);
            var download  = await directory.GetFileClient(shareFile.Name).DownloadAsync();

            var stream = new MemoryStream();

            try
            {
                await download.Value.Content.CopyToAsync(stream);

                return(stream.ToArray());
            }
            catch (Exception e)
            {
                throw new FileshareDownloadException($"The file '{shareFile.Name}{shareFile.Extension}' could not be downloaded", e);
            }
        }