Reputation: 864
I am developing Windows 8 app using C#. Here I am picking the file from my desired Location Using FilePicker, I Know the path of file which I picked from Local drive.
I want to use the File as a Storage file.
StorageFile Newfile = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(Path); // Path is file path
StorageFile file = await KnownFolders.PicturesLibrary.GetFileAsync(Path);
But this is for only where my project located & another one for Load file from Pictures Library. Can any one give me the right Way.
Thanks.
Upvotes: 3
Views: 2992
Reputation: 15296
WinRT has GetFileFromPathAsync()
method of class StorageFile
, but you can not open any file with that method. Only option you have is to use StorageItemMostRecentlyUsedList
class. Which is useful to get the token for all the files that was saved to either most recently used files list or future access list. To save token for the which was accessed from FileOpenPicker
, you need to use StorageApplicationPermissions
class. Here I'm giving you how to save token for a file & how to retrieve token for & access that file.
To save token
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
StorageFile file = await openPicker.PickSingleFileAsync();
if (file != null)
{
// Add to most recently used list with metadata (For example, a string that represents the date)
string mruToken = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.Add(file, "20130622");
// Add to future access list without metadata
string faToken = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file);
}
else
{
// The file picker was dismissed with no file selected to save
}
To retrieve file using token
StorageItemMostRecentlyUsedList MRU = new StorageItemMostRecentlyUsedList();
StorageFile file = await MRU.GetFileAsync(token);
UPDATE
await StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(token);
Upvotes: 5