Вот моя проблема ...
Я проверяю длину строк из текстового файла, по одной строке за раз. Если длина <= 2033, она идет на обработку. Если он> 2033, он попадает в другой файл.
Я бы хотел добавить некоторую информацию в начало файла ошибок. Однако я хочу добавить текст только с первой строкой, которая будет добавлена. Итак, вот что у меня есть:
//Pass the file path and file name to the StreamReader and StreamWriter constructors
StreamReader sr = new StreamReader(inputFile);
StreamWriter sw = new StreamWriter(Dts.Connections["CE802CleanInput"].ConnectionString);
StreamWriter swe = new StreamWriter(Dts.Connections["CE802PreValidationErrors"].ConnectionString);
//Read the first line
line = sr.ReadLine();
while (line != null)
{
int length = line.Length;
if (length > 2033)
{
if // THIS IS WHERE I WOULD HAVE TO ADD THE CONDITION
{
swe.WriteLine("Some records have been rejected at the pre validation phase.");
swe.WriteLine("Those records will not be included in the process.");
swe.WriteLine("Please review the records below, fix and re submit if applicable.");
swe.WriteLine("Input file: " + Dts.Connections["CE802Input"].ConnectionString.ToString());
swe.WriteLine();
swe.WriteLine(line);
count++;
}
else
{
swe.WriteLine(line);
count++;
}
}
if (length <= 2033)
{
sw.WriteLine(line);
}
line = sr.ReadLine();
}