Reputation: 95
I am working with Visual Studio ultimate 2013 and using windows store apps. My visual studio project folder "History"(name of the current project) is located in D:Academic folder. I have created text file in the History project folder. And I want to print the details in text file to a text block.
This code works. According to this, the location of the text file is created in Local Folder.
public History()
{
this.InitializeComponent();
StorageFolder = ApplicationData.Current.LocalFolder;
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
ReadText();
}
async void ReadText()
{
StorageFile file = await StorageFolder.GetFileAsync(filename);
ghij.Text = await FileIO.ReadTextAsync(file)
}
private void Write_click(object sender, RoutedEventArgs e)
{
WriteText();
cdef.Text = "";
}
async void WriteText()
{
StorageFile file = await StorageFolder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);
await FileIO.WriteTextAsync(file, cdef.Text);
}
In my case I don't want to create and write a file,but to READ an already created file which is located in D:\Academic:\History folder. So how can I change the path to access the text file.
Please help.
Upvotes: 1
Views: 633
Reputation: 1620
You don't have direct access in Windows Store Apps. FilePicker
class would serve you most of the time to open a file but if you want a programmatic access to a file then you need to declare appropriate capabilities in your package manifest.
And yes you want to access documents library, in that case you have to declare documents library capability in your package manifest.
From MSDN :
The file picker provides a robust UI mechanism that enables users to open files for use with an app. Declare the documentsLibrary capability only when you cannot use the file picker.
NOTE : Documents library only gives access to file formats filtered by the types declared in the manifest.
For eg. For example, if a DOC reader app declared a .doc file type association, it can open .doc files in Documents, but not other types of files.
You can't use the Documents library in a Windows Phone Store app. You can't publish a Windows Phone Store app that specifies the documentsLibrary capability to the Windows Phone Store. The Store blocks the publishing of the app.
You can refer MSDN Arcticle on Manifest capabilties.
Upvotes: 0
Reputation: 34915
Windows store apps don't have full access to the file system. You can give them access however to specific places like the Documents through the so called capabilities. You can also save and restore content from local storage.
Upvotes: 2