Working with text files
Writing to a text file
public void Writing_to_a_text_file(string message, string logfile, bool newline, bool append)
{
// message : message to be written
// logfile : file path
// newline : true - finish with a new line
// append : true - append to file; false - start a new file
using (var file = new System.IO.StreamWriter(logfile, append))
{
file.Write(message);
if (newline)
{
file.WriteLine();
}
}
}
Create a directory
// Create a directory named "Output" next to the workbook file
string workbookDirectoryPath =
System.IO.Path.GetDirectoryName(Toolbox.CurrentWorkbookPath);
string outputDirectory = System.IO.Path.Combine(workbookDirectoryPath, "Output");
// Verify if directory exists, if not then create it
if (!System.IO.Directory.Exists(outputDirectory))
{
System.IO.Directory.CreateDirectory(outputDirectory);
}