Seems pretty straight forward, i wonder what the problem is ... you're targeting framework 3.5 ok, but SSIS what does that have to do with the matter at hand?
Anyway here's my five cents on a simple program that does that in 3.5
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
namespace ComparingOfFiles
{
class Program
{
static void Main(string[] args)
{
Write("Welcome to file compare program utility, it will generate a file and add some lines, then it will copy it and add more. Finally compare the two and write the added content to a new file.\r\n");
try
{
var parts = Assembly.GetExecutingAssembly().Location.Split(@"\".ToCharArray());
parts[parts.GetUpperBound(0)] = "";
var basePath = string.Join(@"\", parts);
string fileOne = Path.Combine(basePath, "fileone.txt");
string fileTwo = Path.Combine(basePath, "filetwo.txt");
string fileResult = Path.Combine(basePath, "fileresult.txt");
int columns = 8;
string valuerange = "abcdefghijklmnopqrstuvwxyz";
string seperator = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator;
var rnd = new Random((int) DateTime.Now.Ticks);
Write("Deling files if existing");
foreach(var file in new []{fileOne, fileTwo, fileResult})
if(File.Exists(file))
File.Delete(file);
Write("Making log file one");
using (var fs = new FileStream(fileOne, FileMode.Create))
{
var writer = new StreamWriter(fs, Encoding.UTF8);
for (int x = 0; x < 10; x++)
AddColumnsOfRandomWords(columns, rnd, valuerange, seperator, writer);
writer.Flush();
writer.Close();
}
Write("Copying to logfile two and adding some lines");
File.Copy(fileOne, fileTwo);
using (var fs = new FileStream(fileTwo, FileMode.Append))
{
var writer = new StreamWriter(fs, Encoding.UTF8);
for (int x = 0; x < 5; x++)
AddColumnsOfRandomWords(columns, rnd, valuerange, seperator, writer);
writer.Flush();
writer.Close();
}
Write("Comparing the two files");
var sbDifference = new StringBuilder();
var fileOneContentRows = new List<string>();
var fileTwoContentRows = new List<string>();
using (var fs = new FileStream(fileOne, FileMode.Open, FileAccess.Read))
{
var reader = new StreamReader(fs, Encoding.UTF8);
while(!reader.EndOfStream)
fileOneContentRows.Add(reader.ReadLine());
reader.Close();
}
using (var fs = new FileStream(fileTwo, FileMode.Open, FileAccess.Read))
{
var reader = new StreamReader(fs, Encoding.UTF8);
while (!reader.EndOfStream)
fileTwoContentRows.Add(reader.ReadLine());
reader.Close();
}
using (var fs = new FileStream(fileResult, FileMode.CreateNew))
{
int idx = 1;
while (idx < fileOneContentRows.Count())
{
if (fileOneContentRows[idx].Equals(fileTwoContentRows[idx]))
{
idx++;
continue;
}
throw new DataException("OMFG! the logs from last weeks have been changed this week!");
}
if (fileOneContentRows.Count() >= fileTwoContentRows.Count())
{
sbDifference.AppendLine("Log error, the content of the logfile appears to have decreased between one: " + fileOne + " and two: " + fileTwo);
} else
{
for (int z = idx; z < fileTwoContentRows.Count();z++ )
{
sbDifference.AppendLine(fileTwoContentRows[z]);
}
}
var writer = new StreamWriter(fs, Encoding.UTF8);
writer.Write(sbDifference.ToString());
writer.Flush();
writer.Close();
}
Write("Done");
} catch (Exception ex)
{
Write("Exception occured:\r\n" + ex.ToString());
}
Write("\r\nPress ENTER to exit");
Console.ReadLine();
}
private static void AddColumnsOfRandomWords(int columnsToAdd, Random rnd, string valuerange, string seperator, StreamWriter writer)
{
for (int i = 0; i < columnsToAdd; i++)
{
int length = rnd.Next(1, 20);
var word = "";
for (int y = 0; y < length; y++)
word += valuerange.Substring(rnd.Next(valuerange.Length - 1), 1);
if (i < (columnsToAdd - 1))
word += seperator;
writer.Write(word);
}
writer.Write("\r\n");
}
private static void Write(string message)
{
Console.WriteLine(message);
}
}
}