Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Download files on Windows Phone 10 or UWP using C#

$
0
0

I want to download the pdf file from server "http://che.org.il/wp-content/uploads/2016/12/pdf-sample.pdf" and save the same in local.

I using below code to achieve this. however I'm not able to download the pdf file.

I'm using the below code to download.

var uriBing = new Uri(@"http://che.org.il/wp-content/uploads/2016/12/pdf-sample.pdf"); try { // Create sample file; replace if exists. StorageFolder storageFolder = ApplicationData.Current.LocalFolder; StorageFile sampleFile = await storageFolder.CreateFileAsync("Prajesh.pdf", CreationCollisionOption.ReplaceExisting); //var sampleFile = await DownloadsFolder.CreateFileAsync("ManualFile.pdf", CreationCollisionOption.ReplaceExisting); var cli = new HttpClient(); var str = await cli.GetStreamAsync(uriBing); var dst = await sampleFile.OpenStreamForWriteAsync(); await str.AsInputStream().AsStreamForRead().CopyToAsync(dst);// AsStreamForRead().CopyTo(dst); } catch (Exception ex) { }

Is there any other approach to download and save file.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>