Hi i need to write a C# application that runs daily and takes 2 parameters. How to do this?Ho wto write a c# program that accepts parameters at runtime. I need to supply parametrs in command prompt. Can anybody help me?
passing parameters
Collapse
X
-
Tags: None
-
Hi,
I need to run the program in command prompt with two parameters.
Create the .exe for my application(say order.exe) and run it in command prompt as..
order parameter 1 parameter 2.
How to read these passed parameters in the program?Comment
-
Finally after much googling..i got it..i used the string args and .exe.config file....Thanks for ur helpComment
-
string filepath="";
if( args[0].ToUpper() == "TST" && args[1].ToUpper() == "ATS")
filepath=Config urationSettings .AppSettings["TST_ATS"];
//////////////////
i have this tag in the config file..
<add key="TST_ATS" value=@"c:\orde r\ats_attribute ld.txt"/>
///////////////////////
I get this exception when i execute the above code with the two parameters TST ATS
'System.Argumen tNullException
filepath is being null...its not getting the path from the config file.
Any help??????????Comment
-
This is the code for to read the file in c#
using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Configur ation;
using System.IO;
namespace getfiles
{
class Program
{
static void Main(string[] args)
{
string filepath = "";
if (args[0].ToUpper() == "TST" && args[1].ToUpper() == "ATS")
filepath = ConfigurationSe ttings.AppSetti ngs["TST_ATS"];
Console.WriteLi ne("yours Text File Name:= "+filepath) ;
StreamReader strRead = new StreamReader(fi lepath);
string line = strRead.ReadLin e();
Console.WriteLi ne("--------Data in the file------");
Console.WriteLi ne();
while (line != null)
{
Console.WriteLi ne(line);
line = strRead.ReadLin e();
}
strRead.Close() ;
Console.ReadLin e();
}
}
}
///this is the app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<appSettings>
<add key="TST_ATS" value="C:\MSDN\ read.txt"/>
</appSettings>
</configuration>
//// how to execut
getfiles.exe TST ATSComment
Comment