I am new to writing C# programs, actually new to object oriented programming. I normally write programs in PICK. But I have a software package that will call a pre-processor to allow us to modify a text file before it processes a the file from a 3rd party. I have the process working as a stand alone program, but when calling it through the pre-processor it needs to recieve a value back before it will continue the process. I am trying to pass back a "0", but the pre-processor isn't recieving anything. Can anyone give me a hint as to why my program isn't passing anything back?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
class Program
{
//static int Main(string[] args, int good)
static int Main(string [] args)
//static void Main()
{
if (args.Length != 0)
{
//Console.WriteLine("input , {0}", args[0]);
//string origFileName = "csharptest.txt";
//good = 0;
string origFileName = args[0];
string origPath = @"C:\Users\mshepard\test";
string strFileName = System.IO.Path.Combine(origPath, origFileName);
FileStream objFilename = new FileStream(strFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
StreamWriter sw = new StreamWriter(objFilename);
StreamReader objFileRead = new StreamReader(objFilename);
System.Text.StringBuilder listLines = new System.Text.StringBuilder();
try
{
string strFile = "";
while ((objFileRead.Peek() != -1))
{
string[] strValue = objFileRead.ReadLine().Split(new char[] { '|' });
int i = 0;
bool boolFlag = false;
System.Text.StringBuilder strB = new System.Text.StringBuilder();
string s_mod;
foreach (string s in strValue)
{
s_mod = s;
if (i == 7)
{
if (s.ToString() == "INV")
{
boolFlag = true;
}
}
if (i == 18 & boolFlag == true)
{
s_mod = "000000.gif";
}
strB.Append(s_mod + "|");
i += 1;
}
strFile += strB.ToString().Substring(0, strB.Length - 1) + "\r\n";
}
string tempFileName = "temp.txt";
string tempFileLoc = System.IO.Path.Combine(origPath, tempFileName);
System.IO.File.WriteAllText(tempFileLoc, strFile);
System.IO.File.Copy(tempFileLoc, strFileName, true);
System.IO.File.Delete(@"C:\Users\mshepard\test\temp.txt");
sw.Flush();
sw.Close();
}
catch (Exception ex)
{
objFileRead.Close();
objFilename.Close();
}
finally
{
objFileRead.Close();
objFilename.Close();
}
//Environment.Exit(0);
return 0;
}
//Environment.Exit(0);
return 0;
}
}