title: C# Problem incrementing a file name when the file name already exists
body: <p>File name format = 123456.1.pdf
  Example:
  Entered 123456 in the textbox. If a file by that number exists the program would increment the number to 123456.1
  Entered 123456.1 in the textbox. If a file by that number exists the program would increment the number to 123456.2
  Entered 123456.11 in the textbox. If a file by that number exists the program would increment the number to 123456.12</p>
  <p>Problem is when 123456.9 exists, the program increments it to 123456.110 or 123456.1111  What am I doing wrong? Thank you for your help.</p>
  <pre><code>MyWO = WO.Text; 
  string plusOne = MyWO.Substring(MyWO.Length - 1);
  string FnlName;
  int cnt;
  if (MyWO.Length == 8 ) { cnt = Convert.ToInt32(plusOne) + 1; }
  else { cnt = 1; }
  
  while (File.Exists(savePath + MyWO + &quot;.pdf&quot;))
  {
      if (MyWO.Length == 6)
      {
          FnlName = (MyWO + &quot;.&quot; + cnt.ToString());
      }
      else
      {
          string Fnl = MyWO.Remove(MyWO.Length - 1, 1);
          FnlName = (Fnl + cnt.ToString());
      }
      cnt++;
  }
  </code></pre>