title: create textfile dynamically if textfile size exceeds maximum size
body: <p>I'm writing text to files using <code>StreamWriter</code> using the following code:</p>
  
  <pre><code>path == @"Desktop\";
  filepath1 = path + "1.txt";
  StreamWriter _sw = new StreamWriter(filepath1, true);
  _sw.WriteLine("some Text");
  _sw.Close();
  </code></pre>
  
  <p>if size of textfile exceeds 500kb I want to create text files dynamically. I'm tryng following code:</p>
  
  <pre><code>var size = (path.Length)/1024;
  
  if(size&gt;=500)
  {
      int i = (size/500)+1;
      var filepath2 = path + i + ".txt";
  
      if (File.Exists(filepath2))
      {
          StreamWriter _sw = new StreamWriter(filepath2, true);
          _sw.WriteLine("Some message");
          _sw.Close();
      }
  }
  else
  {
      FileStream fs = File.Create(filepath2);
      StreamWriter _sw = new StreamWriter(filepath2, true);
      _sw.WriteLine(ex);
      _sw.Close();
  }
  </code></pre>
  
  <p>My question is if file 2.txt also exceeds 500kb I want to create 3.txt,4.txt..... and so on..
  I want to create all these dynamically - how to solve this problem?</p>