Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / WPF

File Pickers in Windows 8

4.00/5 (1 vote)
30 Apr 2012CPOL 14.3K  
this will shows the File pickers in windows 8

Introduction

In this article I am going to tell about the file pickers in Windows 8 such as file open picker, file folder picker etc.

Background 

This code will helps you to know about the pickers in Windows 8 metro applications.

Using the Code

1.file Open Picker

FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.Desktop;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
openPicker.FileTypeFilter.Add(".rar");
openPicker.FileTypeFilter.Add(".txt");
StorageFile   file = await openPicker.PickSingleFileAsync();
 string  fileName=file.Name;

The above code will open the files like .jpg,.rar,.txt 

In the above code we creating the object for the fileopenpicker() and we are setting the view mode as thumbnail.

And then we are setting the default starting file location as DeskTop or you can choose it as a  

Downloads, Documents, PictureLibrary etc.

And then we are adding the filters to open the files which are in specific format like .txt, .jpg and .rar

Now the method openpicker.PickSingleFileAsync() will open the file chosen by the user

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)