Answered by:
StorageFile::GetFileFromPathAsync does not work

Question
-
Hi all, I try to get file to process in Metro. I use the following code to do, but code run to auto fileOp = StorageFile::GetFileFromPathAsync("D:\\test\\a.docx"); the app hang. Anybody know how to get a StorageFile object from a absolute path?
auto fileOp = StorageFile::GetFileFromPathAsync("D:\\test\\a.docx");
fileOp->Completed = ref new AsyncOperationCompletedHandler<StorageFile ^>([=]IAsyncOperation<StorageFile^>^ a)
{
});
fileOp->Start();
- Edited by Ever Chen Friday, October 21, 2011 10:22 AM
Friday, October 21, 2011 10:14 AM
Answers
-
The picker allows access because the user provided the file to you. Also, they provided the file, not the path. Basically your application using the FilePicker now has access to the stream, not directly to the path. If you set the Documents capability in the manifest then you can programmatically access files that are in the user's Documents folders but not any arbitrary path.
Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuer
(if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others)- Marked as answer by DavidLambMicrosoft employee, Moderator Wednesday, October 26, 2011 4:13 PM
Friday, October 21, 2011 2:45 PM -
You can also access your application's temp folder. See the following thread for an example of that:
Raman
- Marked as answer by DavidLambMicrosoft employee, Moderator Wednesday, October 26, 2011 4:14 PM
Friday, October 21, 2011 9:43 PM
All replies
-
The picker allows access because the user provided the file to you. Also, they provided the file, not the path. Basically your application using the FilePicker now has access to the stream, not directly to the path. If you set the Documents capability in the manifest then you can programmatically access files that are in the user's Documents folders but not any arbitrary path.
Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuer
(if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others)- Marked as answer by DavidLambMicrosoft employee, Moderator Wednesday, October 26, 2011 4:13 PM
Friday, October 21, 2011 2:45 PM -
You can also access your application's temp folder. See the following thread for an example of that:
Raman
- Marked as answer by DavidLambMicrosoft employee, Moderator Wednesday, October 26, 2011 4:14 PM
Friday, October 21, 2011 9:43 PM -
Is it possible to open this limitation in future by MS?Monday, October 24, 2011 9:02 AM
-
I appreciate your feedback in this area! Do you have a particular scenario where the available avenues for accessing files in a Metro style app are not sufficient for your application?
This particular ask on the surface conflicts with the vision of Metro style apps, as Tim put it, having direct access to an arbitrary folder outside of the Windows.Storage.ApplicationData.Current folders since a Metro style app should not be dependent upon a users drive / folder layout or have the ability to manipulate it outside of what was mentioned above.
-David
Wednesday, October 26, 2011 4:13 PMModerator -
Suppose I want to process 100 files from a USB drive directory.
It would be too painful to ask the user to select each one. Why can't the user, at runtime, grant the application the ability to read from or write to any directory (and child directories) they want?
Will Metro force the user to be instructed to use Explorer to copy those files to an application directory?
Wednesday, October 26, 2011 8:49 PM -
I appreciate your feedback in this area! Do you have a particular scenario where the available avenues for accessing files in a Metro style app are not sufficient for your application?
This particular ask on the surface conflicts with the vision of Metro style apps, as Tim put it, having direct access to an arbitrary folder outside of the Windows.Storage.ApplicationData.Current folders since a Metro style app should not be dependent upon a users drive / folder layout or have the ability to manipulate it outside of what was mentioned above.
-David
Thursday, October 27, 2011 6:55 AM -
The picker allows access because the user provided the file to you. Also, they provided the file, not the path. Basically your application using the FilePicker now has access to the stream, not directly to the path. If you set the Documents capability in the manifest then you can programmatically access files that are in the user's Documents folders but not any arbitrary path.
Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuer
(if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others)
Thanks, Tim. We will re-design our product.Thursday, October 27, 2011 6:56 AM -
Suppose I want to build a metro style version of Winamp. How am I supposed to read each file of a playlist of audio files?Friday, August 24, 2012 7:54 PM
-
You cant access that sort of directory from Metro.
It has to be one of the folders in the app manifest and has to be declared in the manifest too.
Beware though. the temp folder files are destroyed when Win 8 closes down.
n.Wright
Friday, August 24, 2012 8:58 PM -
You can use the FolderPicker to let the user explicitly identify a folder. You then have access to any file in the folder or any of its subfolders.Tuesday, September 25, 2012 5:09 PM