title: How can I write this DOS command in C# code?
body: <p>I want to execute all sql files in folders. I found the answer in <a href="https://stackoverflow.com/questions/2583517/run-all-sql-files-in-a-directory">this question</a> is helpful. I can use their command and it works as expect.</p>
  
  <p>I want to run it from C# code. i tried a couple ways but I couldn't get the result. Below is the code that I have tried but not success.</p>
  
  <pre><code>Process process = new Process();
  Process process = new Process();
  process.StartInfo.UseShellExecute = false;
  process.StartInfo.RedirectStandardOutput = true;
  process.StartInfo.RedirectStandardError = true;
  process.StartInfo.CreateNoWindow = true;
  process.StartInfo.FileName = "cmd.exe";
  process.StartInfo.Arguments = string.Format("for %f in ({2}/*.sql) do sqlcmd /S {0} /d {1} /U {3} /P {4} /E /i {5}",
  sqlServerName, databaseName, folder, sqlUserName, sqlPassword, @"""%f""");
  process.StartInfo.WorkingDirectory = @"C:\";
  process.Start();
  process.WaitForExit();
  </code></pre>
  
  <p>I want to know how can I move this DOS command <code>for %f in (*.sql) do sqlcmd /S &lt;servername&gt; /d &lt;dbname&gt; /E /i "%f"</code> into C# code</p>