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.