2013-03-14 2 views
1

Я пытался создать фиксированный длинный (левый выровненный) командный файл с приведенным ниже кодом.Append throwing exception

, когда я использую Append it's throwing exception "является методом, но используется как тип".

  string batFilePath = @"c:\mockforbat.bat"; 
     if (!File.Exists(batFilePath)) 
     { 
      using (FileStream fs = File.Create(batFilePath)) 
      { 
       fs.Close(); 
      } 
     } 

     //write 
     using (StreamWriter sw = new File.AppendText(batFilePath)) 
     { 
      string a = String.Format("{0,-24}{1,-5}{2,5}", "CostCenter", "CostObject", "ActivityType"); 
      sw.WriteLine(@a); 

     } 
     Process process = Process.Start(batFilePath); 
     process.WaitForExit(); 

Пожалуйста, верьте мне, что я сделал неправильно здесь?

+0

что исключение –

+1

Кстати, это не исключение, а ошибка компиляции. –

ответ

4

Отбросьте оператор new от этой линии

using (StreamWriter sw = new File.AppendText(batFilePath)) 

Он должен читать

using (StreamWriter sw = File.AppendText(batFilePath)) 
1
string batFilePath = @"c:\mockforbat.bat"; 
using(var fs = new FileStream(batFilePath , FileMode.OpenOrCreate, FileAccess.Write)) 
{ 
    using(var sw = new StreamWriter(fs)) 
    { 
     string a = String.Format("{0,-24}{1,-5}{2,5}", "CostCenter", "CostObject", "ActivityType"); 
     sw.WriteLine(a); 
    } 
}