File access sample

This sample shows how to create, read, write, copy and delete a file, how to retrieve file properties, and how to track a file or folder so that your app can access it again. This sample uses Windows.Storage and Windows.Storage.AccessCache API.

171,301 times
Add to favorites
E-mail Twitter Digg Facebook
Sign in to ask a question

  • Read file from Documents to string
    1 Posts | Last post June 23, 2014
    • How read .txt file from Documents Library into string in Page Consructor.
  • Hello How can access the file from written path .
    1 Posts | Last post May 07, 2014
    • StorageFile file = await StorageFile.GetFileFromPathAsync(@"C:\MyApp\mytext.xml");
      I want to access the file like this.
  • Good sample code
    5 Posts | Last post April 22, 2014
  • File not found
    2 Posts | Last post April 20, 2014
    • I´m a begginer and maybe this is a silly question.
      I want to read a .txt from Local folder and I´m using this code:
      public async void ReadTimestamp()
            StorageFile sampleFile = await localFolder.GetFileAsync("dataFile.txt");
            String timestamp = await FileIO.ReadTextAsync(sampleFile);
            tb_salida.Text = timestamp;
         catch (Exception)
            tb_error.Text = "Not found";
      I always read "Not found", I don´t know what folder I have to use to put my file into it. So the thing is: I don´t know which is the Local Folder. I tried to put my file in many places (Assets, bin, Common...) and the other two upper folders.
       Sorry about my English and thanks.
    • one solution is to place your file in the same location as that of the .exe. make use of the Environment class to get access to this folder
      hope this helps!
  • Exception of "KnownFolders.DocumentsLibrary"
    3 Posts | Last post October 23, 2013
    • 1. I can't open the solution using Visual studio Express 2012 for Windows phone in windows phone 8 RTW(SDK 8.0)
      2. When i try to use the "StorageFolder storageFolder = KnownFolders.DocumentsLibrary;"
      in my project, it raises the "NotImplementException". (SDK 8.0)
      Can anybody help to answer my question?
    • 1) This is a Windows 8.1 application. Of course you can't open it in Windows Phone 8.
    • This not run in Windows Phone, for it is needed some adjustments
  • Javascript doesn#t work on Win7 with IE9
    2 Posts | Last post August 16, 2013
    • Hi,
      I tried to use the javascript but it doesn't work.
      I use IE9 on Win7.
    • This is a Windows 8 application and the javascript with HTML is just another way to develop Windows 8 applications.
  • The Write a File doesn't show how to overwrite a file
    3 Posts | Last post February 27, 2013
    • If a file exists, writing to it will only replace the first n bytes that are being written, leaving the rest behind. How can I overwrite a file?
    • Hey David, you can truncate the content of the file by assigning a value to the size property of the acquired read/write stream. In this case if you want to reset only what is left behind you can assign the number of bytes n that you just wrote to the size. You can also start from a clean file if you go assign zero to the size of the stream before you write to it.
    • // Overwite use CreationCollisionOption.ReplaceExisting
         StorageFile file = await crmImgsFolder.CreateFileAsync(TEMPFOLDER_IMAGEPREFIX + id.ToString(), CreationCollisionOption.ReplaceExisting);
  • Accessing Files in Background task..
    1 Posts | Last post December 20, 2012
    • I want to read files from system and update the tiles... by using background is my code of backgroundtask... my code is in c++.
      But i am not able to read the file.. it is working in MainPage.xaml.cpp but not in BackgroundTask... Class1.cpp
      void Class1::Run(IBackgroundTaskInstance^ taskInstance)
      	BackgroundTaskDeferral^ deferral = taskInstance->GetDeferral();
      void Class1::Notifications()
      create_task(KnownFolders::DocumentsLibrary->GetFileAsync("12.txt")).then([this](task<StorageFile^> getFileTask)
          {  auto _sampleFile = getFileTask.get();
      		if (_sampleFile != nullptr){
              create_task(FileIO::ReadTextAsync(_sampleFile)).then([this](String^ fileContent)
      		Sting^ readFile = String^ fileContent;
      	catch(Exception^ ex)
  • Accessing Files in Background task..
    1 Posts | Last post December 18, 2012
    • I need to read some files and update the tiles automatically which are in my system.. by using background task but.. i am not able to do it.. can any one help me 
  • Accessing files from other than KnownFolders
    5 Posts | Last post December 08, 2012
    • What has changed around accessing folders that do not exist in the KnownFolder class?  For instance, say the OEM wants to parse all of the OEM#.INF files from the "c:\\Windows\\Inf" directory using code?  What is the CORRECT WINDOWS 8 way to authenticate the process and gain programatic access to the folder in order to return the OEM#.inf files?
    • Hi Christian,
      With regards to your question, this depends on the type of application that the OEM is trying to develop. If this is a Desktop application you should still be able to have access to the folder just as in the past. However if this is a Metro style application then it will only have acess to locations defined by its capabilities:
      * How to specify capabilities in a package manifest:
      * Access to user resources using the Windows Runtime:
      Therefore, the Windows folder will not be programatically accessible in Metro Style applications unless user selected through the File Picker (
    • After re-reading my response I noticed that my last statement was partially incorrect. For Metro Style applications, those directories which are not part of the user resources or supported locations can be accessible through the File Picker. However, the Windows directory is special such that it is not accessible through Metro Style applications. Have you considered using AppData to store those OEM#.inf files instead?
    • Thank you, Elmar!!  This is what I thought was the case!  I just created a desktop app and got to the info that way...  It is pretty clear that tool development will be fairly limited to desktop apps.
    • This was very interesting. Thanks for the sample and the comments.
1 - 10 of 14 Items