passing parameters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kewldudehere
    New Member
    • Jan 2007
    • 58

    passing parameters

    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?
  • bplacker
    New Member
    • Sep 2006
    • 121

    #2
    a little more clarification would be nice.

    but yes, it is possible to pass parameters to a function at the command prompt as far as I know.

    Comment

    • kewldudehere
      New Member
      • Jan 2007
      • 58

      #3
      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

      • bplacker
        New Member
        • Sep 2006
        • 121

        #4
        well as soon as the user hit enter, you could say console.readlin e(), and get the two parameters and pass them to a function or use them in that 'program', whichever you want.

        Comment

        • kewldudehere
          New Member
          • Jan 2007
          • 58

          #5
          Finally after much googling..i got it..i used the string args and .exe.config file....Thanks for ur help

          Comment

          • kewldudehere
            New Member
            • Jan 2007
            • 58

            #6
            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

            • GRDev
              New Member
              • Jan 2007
              • 3

              #7
              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 ATS

              Comment

              Working...