Answered by:
how to get file from temp foldre using StorageFile.GetFileFromPathAsync()

Question
-
Hi,
I am trying to download a .pdf in the temp folder.
Here is the code
var uri = new Uri("http://www.nakcollection.com/uploads/7/7/7/4/7774039/the_man_in_the_red_underpants_book.pdf"); StorageFolder folder = ApplicationData.Current.TemporaryFolder; StorageFile file = await folder.CreateFileAsync("one.pdf"); BackgroundDownloader download = new BackgroundDownloader(); DownloadOperation downloader = download.CreateDownload(uri, file); StorageFile file1 = await StorageFile.GetFileFromPathAsync("");
Now I want to use that file how can I get that file usingStorageFile.GetFileFromPathAsync("");
samEE
- Edited by Sameel Nawaz Wednesday, April 22, 2015 12:51 PM
Wednesday, April 22, 2015 12:17 PM
Answers
-
Hi Sameel Nawaz,
Please try to use the following code to see if it works:
StorageFile file1 = await StorageFile.GetFileFromPathAsync(file.Path);
Besides, I will recommend you use the StorageFile.GetFileFromApplicationUriAsync to get the StorageFile.
var uri = new Uri("ms-appdata:///temp/one.pdf"); StorageFile file1 = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(uri);
Best Regards,
Amy Peng
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Edited by Amy PengMicrosoft employee, Moderator Thursday, April 23, 2015 9:57 AM
- Marked as answer by Sameel Nawaz Thursday, April 23, 2015 5:22 PM
Thursday, April 23, 2015 9:56 AMModerator -
Thanks, a lot it worked :)
Here is the revised version of the code. It might help others too. :)
var uri = new Uri("http://www.nakcollection.com/uploads/7/7/7/4/7774039/the_man_in_the_red_underpants_book.pdf"); StorageFolder folder = ApplicationData.Current.TemporaryFolder; StorageFile file = await folder.CreateFileAsync("one.pdf",CreationCollisionOption.ReplaceExisting); if(file !=null) { //Download form uri to file BackgroundDownloader download = new BackgroundDownloader(); DownloadOperation downloader = download.CreateDownload(uri, file); //set download priority downloader.Priority = BackgroundTransferPriority.High; //request uncontrained download UnconstrainedTransferRequestResult result = await BackgroundDownloader.RequestUnconstrainedDownloadsAsync(new DownloadOperation[] { downloader }); // start downloading await downloader.StartAsync(); //the download is now finished var tempUri = new Uri("ms-appdata:///temp/one.pdf"); StorageFile file1 = await StorageFile.GetFileFromApplicationUriAsync(tempUri); if (file1 != null) { //user defined function for further usage of file LoadFile(file1); } }
samEE
- Marked as answer by Sameel Nawaz Thursday, April 23, 2015 5:24 PM
- Edited by Sameel Nawaz Thursday, April 23, 2015 5:30 PM
Thursday, April 23, 2015 5:24 PM
All replies
-
Hi Sameel Nawaz,
Please try to use the following code to see if it works:
StorageFile file1 = await StorageFile.GetFileFromPathAsync(file.Path);
Besides, I will recommend you use the StorageFile.GetFileFromApplicationUriAsync to get the StorageFile.
var uri = new Uri("ms-appdata:///temp/one.pdf"); StorageFile file1 = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(uri);
Best Regards,
Amy Peng
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Edited by Amy PengMicrosoft employee, Moderator Thursday, April 23, 2015 9:57 AM
- Marked as answer by Sameel Nawaz Thursday, April 23, 2015 5:22 PM
Thursday, April 23, 2015 9:56 AMModerator -
Thanks, a lot it worked :)
Here is the revised version of the code. It might help others too. :)
var uri = new Uri("http://www.nakcollection.com/uploads/7/7/7/4/7774039/the_man_in_the_red_underpants_book.pdf"); StorageFolder folder = ApplicationData.Current.TemporaryFolder; StorageFile file = await folder.CreateFileAsync("one.pdf",CreationCollisionOption.ReplaceExisting); if(file !=null) { //Download form uri to file BackgroundDownloader download = new BackgroundDownloader(); DownloadOperation downloader = download.CreateDownload(uri, file); //set download priority downloader.Priority = BackgroundTransferPriority.High; //request uncontrained download UnconstrainedTransferRequestResult result = await BackgroundDownloader.RequestUnconstrainedDownloadsAsync(new DownloadOperation[] { downloader }); // start downloading await downloader.StartAsync(); //the download is now finished var tempUri = new Uri("ms-appdata:///temp/one.pdf"); StorageFile file1 = await StorageFile.GetFileFromApplicationUriAsync(tempUri); if (file1 != null) { //user defined function for further usage of file LoadFile(file1); } }
samEE
- Marked as answer by Sameel Nawaz Thursday, April 23, 2015 5:24 PM
- Edited by Sameel Nawaz Thursday, April 23, 2015 5:30 PM
Thursday, April 23, 2015 5:24 PM