title: StreamReader Could not find file (Because it is not being created)
body: <p>I am trying to create a file for the further write to and read from. </p>
  
  <p>I use Directory.CreateDirectory and File.Create but neither path nor file are being created.</p>
  
  <p>On the Page which part I show here below I check if File exists, and if not, I create a File. On Second Page (that I dont show here) I add new lines to the file using StreamWrite. When saved, first Page comes to focus again and lists the content of the File(only one row in this study).</p>
  
  <p>Here is my code for the part in question:</p>
  
  <pre><code>public async Task ReadFileAsync()
      {
  
  
          string directoryName = Path.GetDirectoryName(@"C:\Users\...\DataBase\");
          Task.Run(async() =&gt; Directory.CreateDirectory(directoryName));
          Task.Run(async() =&gt; File.Create(directoryName + "ProductsDatabase.txt"));
  
          //code for reading from file
          string path = (directoryName + "ProductsDatabase.txt");
  
          using (StreamReader ProductsDatabaseRead = new StreamReader(File.OpenRead(path)))
          {
              ProductOneTextBlock.Text = ProductsDatabaseRead.ReadLine();
  
          }
          if (ProductOneTextBlock.Text == "")
              {
              ProductOneTextBlock.Text = "Nothing to show";
              }
      }
  </code></pre>
  
  <p>The file and folder are not being created. </p>
  
  <p>I don't get any error.</p>
  
  <p>I tried also different folders on the drive in case if there was READ ONLY folder in solution folder. No difference.</p>
  
  <p>Anyone could help? 
  (I found many threads about this problem but here I cannot resolve it with none of the solutions.</p>
  
  <p>Physical file is not being created.</p>
  
  <p>When I attempt to write to it (from another page) I get error that the file could not be found(because it is not there indeed).</p>
  
  <p>It seems that program loses itself somewhere between </p>
  
  <pre><code>Task.Run(async() =&gt; Directory.CreateDirectory(directoryName));
          Task.Run(async() =&gt; File.Create(directoryName + "ProductsDatabase.txt"));
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>using (StreamReader ProductsDatabaseRead = new StreamReader(File.OpenRead(path)))
          {
              ProductOneTextBlock.Text = ProductsDatabaseRead.ReadLine();
  
          }
  </code></pre>
  
  <p>, as TextBlock is not being updated even if ProductsDatabaseRead is null.</p>
  
  <p>If I put </p>
  
  <pre><code>ProductOneTextBlock.Text = "Nothing to show";
  </code></pre>
  
  <p>a the begining of the method, TextBlock gets updated.</p>
  
  <p>SO, why the</p>
  
  <pre><code>using (StreamReader ProductsDatabaseRead = new StreamReader(File.OpenRead(path)))
  </code></pre>
  
  <p>does not work?</p>