title: Restrict my code to write to a specific folder C#
body: <p>I got a folder in C called &quot;donotcopy&quot;. I want to protect it and no matter what not to be allowed to create files within.</p>
  <p>My intuitive solution was just to create a str with same name and where user enters a destination it just checks if it's the same.</p>
  <p>Example:</p>
  <pre><code>class FileCreation
  {
      public static void Main()
      {
          string notallowed = (&quot;c:\\donotcopy&quot;);
          string filename = (&quot;Nick.txt&quot;);
  
          Console.WriteLine(&quot;Enter the full path to create an empty file.&quot;);
          string path = Console.ReadLine();
          path = path.ToLower();
  
          while (notallowed == path)
          {
              Console.WriteLine(&quot;The chosen path is not allowed please try another one.&quot;);
              path = Console.ReadLine();
              path = path.ToLower();
          }
          using (FileStream fs = File.Create(path + filename)) ;
      }
  }
  </code></pre>
  <p>The problem is if the user enters the destination as &quot;c:.\donotcopy&quot; it will still create the file inside the restricted folder.</p>